Lecture Materials

Questions & Answers


Q: could yall explain what just happened once more?

A1:  Absolutely! Thank you for asking!


Q: so we always have to define foo first?

A1:  Yes! Inside the experimental server you have to define the function before calling/using it :)


Q: example

A1:  Got it!


Q: can you go over number 3 on the slides again?

A1:  Yep! In case you missed it, When we called foo, we passed in (8, 2) as the arguments. Foo as a function substracts the second parameter from the first and then returns that new value + 1. So with this example that would be x = 8 - 2 = 6. Then 6 + 1 = 7 is returned from foo. We said y = foo(8, x) (this was the 8,2 from earlier). So now y = whatever was returned from foo which was 7. Then the print statement prints the x,y in main (caller() here). x still equals 2 because we didn’t change it but y now equals 7 because we updated its value.


Q: Can you go over how y = 13 in foo() wouldn’t change the output?

A1:  Yes! So the y in foo is completely separate from the y in main. The key takeaway is that variables in different functions can have the same name but they are not related. Kinda like how there are other Daniels in the world but you don’t know all of them/they aren’t the same person :) Please follow up if you have more questions!


Q: Thank you!

A1:  Of course :)


Q: Why is y=4 there then?

A1:  Great question! The caller originally decided that y should equal 4. But then they decided they wanted to update it’s value. Although this problem doesn’t have a specific use it was meant to illustrate how we can update variable values with return values


Q: to check if even or odd, is okay to do if x % 2: instead of writing if x % 2 == 1:?

A1:  I tried it in the experimental server and it wasn’t working for me.


Q: How do you make a canvas or do we not need to worry about that right now?

A1:  There’s a line. I believe we always give it to you (like we did with the Bit command)

A2:  It’s canvas = DrawCanvas(width, height)


Q: Hi! I hope you are good today! what does canvas.fill_rect do?

A1:  I am! Hope you are doing well too! canvas.fill_rect draws a rectangle completely filled in (not just the border colored)


Q: How do you make a function paramater optional?

A1:  Great question! I don’t think you can in Python but let’s ask Juliette at the end.


Q: follow up question to the last one, then is it okay to write x & 1 in place for x % 2, so if x & 1:

A1:  We prefer that you use the % to check for even/odd. I tried it in the hack mode interpretor and x & 1 works though


Q: do you need to first draw a rect to fill it in?

A1:  No :)


Q: What color will shapes be if we don't use the color = function?

A1:  White I believe


Q: Is there a way to call the canvas size? Similar to how we had image.width and image.height.

A1:  Yep going to go over it soon :)


Q: Also can we pick specific RGB values for shapes or just set colors like 'red,' 'green,' 'blue,' etc?

A1:  There’s a bunch of colors. You don’t set the individual RGB you just put in a color name. I believe the handout will have the colors :)


Q: How are we accessing canvas? Does it come with python or do we import it from somewhere?

A1:  We import it. DrawCanvas was built on top of Python’s built in TK Drawing System https://web.stanford.edu/class/archive/cs/cs106a/cs106a.1216/handouts_w2021/reference-draw.html


Q: How do we differentiate from left top of the canvas and left top of the oval?

A1:  Great question! Like with images, we have to do some math do to get the correct coordinates. I answered a question but it may not have been yours so please follow up if you still have questions!


Q: I was wondering where we should check if our regrade request on the quiz was succesful? Will our grade automatically be updated on gradescope? Thank you!

A1:  Great question! I’ve never submitted a regrade request on gradescope so I’m not sure but I’ve added this question to the list to ask Juliette at the end :)


Q: How do you get the parameters in parenthesis to go on different lines? Like how many indents would it be to get it perfectly aligned?

A1:  The way that I do this is type out all the parameters on the same line. Then I figure out where I want to split it onto two lines (because the line is way too long) and then I hit enter and Pycharm automatically indents it for me. The exact number of indents varies based on how long the function name is. When I manually did it, I used 4 tabs to get the first parameter on the second line lined up with the first parameters on the first line :)


Q: if I want to find the location of a specific (x,y) in a grid, what function can I use?

A1:  There is not a way to get an (x, y) location based off a grid value. If you are looping through the grid with nested for loops, you can print the x and y for the current iteration. Here’s the grid reference with the available grid functions: https://web.stanford.edu/class/cs106a-8/handouts_w2021/reference-grid.html


Q: Will the coordinates of the inset oval always be left + 20 and top + 20 or will the number added vary on the side of the oval?

A1:  In this example yes but in general no. Hardcoded numbers like the 20 here rarely translate across examples :)


Q: What lectures should we use for Assignment 4?

A1:  Assignment 4 is all about strings, lists, and file reading. So I think the core lectures are 10-13.


Q: is the y add always the same?

A1:  This line of code is a pretty common pattern. y_add does vary with different problems in different scenarios but you will use this pattern pretty frequently


Q: I was trying to work on check_move() for the assignment and for the corner case, I am not sure which function to use to see if the destination value is a corner case since I dont know the location of x_to and y_to

A1:  Great question! LaIR and Juliette and Tara’s office hours is definitely a great place to stop by for homework help (LaIR is open today from 5-7pm PT and Tara has office hours from 6:30-8pm today). With that said, here’s some tips. Think about makes a corner move different from a straight down move (what’s different about the coordinate). Drawing a picture can be super helpful here!


Q: When do we get our quiz grades

A1:  Quiz grades are out as of yesterday afternoon! See the announcement on the course website to access your grade on Gradescope


Q: What was a good score on the quiz/ the average?

A1:  live answered


Q: What do you consider a good grade on the quiz?

A1:  live answered


Q: Are there lair other than Tuesday

A1:  Yes! LaIR is open M/W 5-7pm PT and Tu/TH 7-9pm PT

A2:  https://web.stanford.edu/class/cs106a-8/restrictedSum/zoominfo.html LaIR schedule under the LaIR tab


Q: How do we login to gradescope? do we sign in with school credentials

A1:  Make an account with your Stanford email