July 7th, 2021
Q: Hi! I just had a quick question before we start. Which lectures will the quiz coer?
A1: Through lecture 8!
Q: Last time you said 1-7, so it’s now 1-8? Thanks!
A1: Yep! I didn’t know that strings 1.0 were on the quiz as well. To clarify, quiz 1 covers lectures 1-8. Sorry for the confusion!
Q: can you subtract a char with an int?
A1: Can you clarify what you mean?
Q: Follow up: in other languages how ‘a’ is 91, so you can turn any alphabet by doing ‘the character’ - ‘a’
A1: Great question! Python still uses unicode 8 like other languages. I tried it in the hack mode interpretor (‘c’ -‘a’) and I recieved an error
Q: Why do you check 3 and 14 as a string as oppose to just a number?
A1: When there’s quotes around the numbers it’s a string representation of a number (rather than an integer representation). To use the string functionality such as in you must work with strings not ints :)
Q: how to you sign up for IG?
A1: You sign up for an IG on paperless.stanford.edu. You click the three white bars in the upper left corner (next to CS198) and then in the drop down menu click IG signup. You cannot signup for an IG until your SL opens up time slots :)
Q: If I used or instead of and would any answer with the numbers 3 and 14 return True? Also could you go back over the difference between print vs return True/False? WOuldn't the same result appear?
A1: Great questions! Yes if you used or anything with ‘3’ or ’14’ would return True. Printing “returns” information to the user in the terminal. Return passes information between functions. Please follow up if you have more questions!
Q: Why doesn't the has_pi code always return False? To clarify: if both '3' and '14' are in s it would return True, and then wouldn't it exit the if-statement and then return False?
A1: Yes if both ‘3’ and ’14’ are in the string then True will be reutrned. Once a return statement is hit/processed the function immediately ends and no futher lines are processed.
Q: can you say if a[0] in b or b[0] in a: ?
A1: Yes! That statement would return true if the first character in a is in b OR if the first character in b is in a.
Q: is there a way to test if the variable is None?
A1: Yep if variable == None :)
Q: If instead or returning a boolean we changed a value like a = 'abc' and used that syntax, would the value of a change again? Something like if a = 'a' a = 'abc' a = 'b' return a would this return 'b'?
A1: Yes if the code looked like this: if a == ‘a’: a = ‘abc’ elif a == ‘b’: return a If a did equal ‘b’ then a which is ‘b’ would be returned. Please follow up if I didn’t answer your question :)
Q: If we are having trouble with assignments, can we also email Tara or Julliete directly (I'm assuming yes, but I'm just curious)?
A1: Yes, but we much prefer if you come to their office hours or LaIR (1-1 homework help with a section leader). It’s incredibly difficult to debug code and clarify misconceptions over email. You can also reach out to your section leader or post on Ed to get help :)
Q: following up what if there wasn't an elif and it just simply said if a = 'abc' a = 'a' a = 'b' return a would this return a's value as 'b' or 'a' . Just like the boolean example where we had something like if a = 'b': return True return False but instead of returning a boolean we are changing a variable
A1: To the first block of code, yes a would be returned and a = ‘b’.
Q: is it okay to name ans instead result? Is that okay for style?
A1: Yeah that would be okay. As long as your variable names are descriptive (meaning you can read the name and know what it stores), you can be creative with your naming. result is very very common variable name in coding though.
Q: Where can we access our grades? My section eader sent an email saying everything for our section was graded and posted but I can't seem to find where?
A1: Great question! You can view your grades on paperless.stanford.edu. You might not be able to view your grade until you have your IG with your section leader.
Q: Can you explain again why we make it lower case to work for the catty code?
A1: Yes! Uppercase and lowercase letters are different in Python. ‘C’ does not equal ‘c’. So to do the comparison we have to make all the letters the same case.
Q: Can't you just use if instead of elif?
A1: It depends. If you only want the code to run on certain cases you have to use if/elif/else strategy if you don’t have return statements in your if statement code body.
Q: why does leaving out the ‘el’ in elif change the outcome? taking out the el in my code returns an incorrect solution
A1: This is because you are turning it into an if statement. Each if statement will run if the condition is met. Using elif means only one of the if/elif/else will run (i.e. if the if code runs then the elif/else code will not run)
Q: Are quizzes weighted more than other assignments in this class?
A1: Yes. The grade break down is 50% assignments, 40% quizzes, and 10% section participation. Since there are only 2 quizzes each quiz is worth 20% of your grade. There are many assignments (around 6 or 7 but the exact number hasn’t been determined yet). The assignments are not all weighed equally though (the later assignments are worth more than the earlier assignments).
Q: Is elif like else if in Java?
A1: Yep :)
Q: could you have multiple elifs then?
A1: Yep :)
Q: when there are three tests i see the order goes if, elif, else. on my 2.2 homework, i used if, if, if (with no elif or else). is that ok?
A1: It depends if you want all three tests to run or not. elif isn’t used super often and since you did not know about it for homework 2 you do not need to use it.
Q: will hw 3 be posted today?
A1: Great question! I’m not sure. Probably but let’s ask Juliette at the end :)
Q: Is there any way we can make ‘find’ not be case sensitive?
A1: You could use .lower to make the strings the same case but otherwise no
Q: Can you please explain again what’s the difference of elif versus a stand alone if
A1: Of course! Let’s first start with if/else: if a == ‘1’: do something else: do something else In this body of code if a == ‘1’ the else code will never run. Let’s look at another example: if a == ‘1’: do something elif a == ‘2’: do a funny dance else: walk around In this code, first it will check if a equals ‘1’. If it does, do something will run. Otherwise it will check if a equals ‘2’, a funny dance will be done. Otherwise, walk around will be done. In this structure, once one condition has been met, the other if/elif/else code will not run. If you have 2 adjacent if statements, then the both if statements could run because they are independent (while if/elif/else are dependent on each other).
Q: Is there a way to do an inclusive string that would include the second number?
A1: Slices will never be inclusive of the last index. If you want the second number you should put last number + 1 as the final index
Q: is there an option where the second element is actually the length of the substring you want? Such as .substr in C++
A1: mmmm I don’t think so. At least not a function that’s discussed in this class.
Q: So are s[:4] and s[0:4] the same?
A1: Yes :)
Q: Will we have a final exam in this class?
A1: We don’t have a technical final exam in this class. You will have 2 quizzes in this class. One on Friday wk 3 (this Friday) and another on the Friday of wk 7 (Aug 6th) (the week before the class ends).
Q: the time complexity for both find() [:] are all O(n) where n is the length of the string right?
A1: Yeah I believe so. We don’t talk about time complexity until the next class in C++ so I’m not familiar with the time complexity of the built in Python functions.
A2: But thinking it through, the whole string could need to be searched which would equate to O(n)
Q: Why did she write left+1 instead of left + 1 (with spaces)?
A1: Just a typo. You should have spaces between your mathematical operators (for good style but functionally both work)
Q: Can you explain the + 1 again please?
A1: Yes! We used .find to find the index of the ‘[‘ and ‘]’. When taking slices we start at the first index and go up to but not including the last index. We want the characters between the brackets. So, we want to start one place after the ‘[‘ index and go up to but not including the ‘]’ index.
Q: Where can I find the recorded lectures?
A1: Great question! On the course Canvas page under the Panopto Course Videos (on the sidebar)
Q: I see on the little “covid-19 edition” section of our cs106a class website it says “same great projects.” will there be a project we can do at the end of the quarter? if not, what are some projects we could work on by ourselves?
A1: Yes there is an optional project at the end of the quarter. More info to come soon.
Q: I still don’t understand the negative indexing
A1: Play around with it in the interpreter. But don’t worry too much about it. It is an optional feature.
Q: When is lair?
A1: M/W 5-7pm PT, Tu/Th 7-9pm PT
Q: Will HW be posted today?
A1: HW 3 is coming out later today
Q: so will this be on the quiz since strings will be on the quiz?
A1: No only strings 1.0. No .find(), slices, in etc. Quiz 1 covers Lec 1-8
Q: In sections this week, we’ll go over practice problems to study for the quiz Friday correct? :)
A1: 1 grid problem and then quiz review
Q: Studying the practice quiz is enough to get a great grade in this weeks quiz?
A1: Understanding your homework, doing the extra section problems, and doing the extra problems in the quiz review handout are good preparation. You need to do more than the Bluebook practice quiz.
Q: I know it is a bit late but for the bluescreen assignment, how do we import the images into Pycharm? I was a bit confused on how to put my images into the code
A1: Hi! Drag your image files into the same folder and then you can use their file names in the command line. Post on Ed or come to LaIR tonight if you want help
Q: Sorry where are the actual practice problems posted again? for us to study from
A1: https://web.stanford.edu/class/cs106a-8/handouts_w2021/quiz1-review.html
Q: Will this quiz have pycharm questions as well as bit?
A1: Nothing Pycharm specific.
Q: Where can I find the bluebook practice quiz?
A1: https://web.stanford.edu/class/cs106a-8/handouts_w2021/bluebook_info.html
Q: is it okay to use visual studio code instead of pycharm?
A1: We only offer support for pycharm but you can code in whatever you’re most comfortable with :)
Q: If we still are working on the 2b-2c assignment, does the Grace Period currently apply?
A1: Yes, the grace period continues until Thurs @ 11:55pm PT
Q: Quiz is open booki?
A1: Any static resources.
Q: should our code on the quiz have comments?
A1: No comments necessary on the quiz
Q: Once we answer a question can we go back?
A1: Yes you have access to all questions throughout the entire quiz
Q: Do we need to have Doctests on the quiz?
A1: No doctests on this quiz. But it will be on homework 3 and is fair game for the next quiz
Q: what if you type in another language?
A1: Programming wise: answers to the questions need to be written in python
Q: and you cant actually run your code right?
A1: Yeah you cannot run your code and you cannot copy/paste into/out of Bluebook