Lecture Materials

Class Announcements

  1. Assignment 1 Due Tuesday: We have covered everything you need for assignment #1. It is due on Tuesday. Submission instructions will be available soon.
  2. LaIR is open: See the Zoom info link on the main page for hours.


Questions & Answers


Q: in sections, can we ask questions about the homework? i.e. i’m struggling with the triple problem

A1:  live answered

A2:  You can ask your section leader conceptual questions or brief questions before/after section but in general LaIR is the place to go for homework help. More info here: https://web.stanford.edu/class/cs106a-8/handouts/generalInfo.html


Q: What is LaIR?

A1:  LaIR is the place to get one-on-one homework help. More info here: https://web.stanford.edu/class/cs106a-8/handouts/generalInfo.html

A2:  live answered


Q: What is LaIR?

A1:  live answered


Q: one more q, sorry! do we have homework on fridays or is that day completely off?

A1:  No apology needed! Please ask all your questions! Friday is a day off! You can work on your homework and you may have section depending on what day your section is. But there is no lecture (On 2 Fridays there will be a quiz during class time)


Q: so what are sections for?

A1:  Sections are for working on extra problems with your section leader, conceptual review, work with your peers, and ask questions


Q: where can we find the section zoom links?

A1:  You can find your section Zoom link on paperless


Q: how do we hand in the homework

A1:  It will be on the homework handout later today


Q: Where can we find the section handouts? I don’t believe they’re listed under the sections tab on the website

A1:  https://web.stanford.edu/class/cs106a-8/sum-section/section1/section1.html Here’s the link and it should be posted on the website later today!


Q: Will the homework that’s due on tuesday be graded with the scale that’s shown on the class website?

A1:  Yes!


Q: In python do we have to say if the variable is a character, an integer, etc when declaring? Like other programming languages

A1:  No. Variables are not explicitly typed in python


Q: are you allowed to use variables to solve bit problems?

A1:  You can only use the commands listed on the bit reference sheet

A2:  No


Q: What time will quizzes and exams be on fridays?

A1:  During lecture time 1:30-2:30pm PST unless you have a time zone or academic conflicit in which case you should contact the head TA Tara to arrange another time to take the quiz


Q: Can we do XYZ = 'red' ?

A1:  Yes. Variables can have any name (although descriptive names are good style)


Q: Can a variable store a command? ex. move = bit.move()

A1:  Yes! But you cannot use variables on your bit homework


Q: Should our homework have comments?

A1:  Yes! In line comments to describe dense or confusing lines of code and a brief comment about what the program does it good to have. More style details will be release


Q: I didnt understand the question of "can we use functions as varaibles", can you please explain?

A1:  Yes! This is an advanced concept so you’re no expected to understand. Variables in python are not explicitly typed like they are in other programming languages so a variable in python can equal anything including a function.


Q: Storing functions as a variable is not common in Python, but very common in JavaScript, why is that? Is there something about these two languages that make it so

A1:  This is an excellent question that I do not know the answer to. At the end, we can ask Juliette to see if she knows the answer


Q: Can we use variables on our homework now that we have learned them?

A1:  No you cannot. You can only use the commands listed on the bit reference sheet


Q: just follow up on the previous question - will we get penalised if we don’t have comments descibing the codes in our homework?

A1:  Comments are encouraged for the first assignment.


Q: Can you explain the coordinate system again?

A1:  Thanks for asking! The origin (0, 0) is in the upper left corner (different from the math coordinate system where (0, 0) is in the lower left). As a result, the y values grow down and the x values grow to the right.


Q: How long (on average) should our assignments take us? I know that bugs in our code will obviously vary that time, but what is your best guess?

A1:  This is a tricky question because it varies for everyone. CS106A is a 5 unit course so you can expect to have 10hours of work outside of class (and potentially more because this is an excellerated 8 week course). But this is just a general estimate. The bit homework took me longer than 10 hours but my friends shorter than 10 hours. There are so many variables depending on how much coding experience you have, you well you concpetually understood the topics etc.


Q: Should we use cammel case for variables/do you use it for functions?

A1:  In python we use underscore separate names for variables and functions.


Q: is SimpleImage built in or from a library?

A1:  SimpleImage is a library


Q: What kind of space is the image variable setting aside for the image file?

A1:  I believe it’s stack memory.


Q: Is pixel.red all the red pixels or just one? If it’s just one how do we do all?

A1:  pixel.red accesses the red channel for one pixel named pixel. We could have named the pixel anything but pixel is a good descriptive name. To access all the pixels we have to use a for each loop (or a for range loop)


Q: What does “return image” do?

A1:  Return image returns the updated image to the caller function.


Q: Does this not need two nested for loops in order to loop through both the x and y coordinates in the image?

A1:  There are two types of for loops: for each loops and for range loops. For each loops automatically iterate over all pixels. When using for range loops we have to use nested for loops to access all the pixels (coming soon!).


Q: Are we allowed to use for loops in the bit homework, now that we have learned them? I have noticed a couple cases when working through the problems where they may have been useful.

A1:  No you cannot.


Q: If I want to change pixel(14,25) only, then how to do so?

A1:  You’ll learn about a command called image.get_pixel(x, y) soon!


Q: I’m not sure if this is a bad question but where does “pixel” come from/how does python know that is a pixel. Can I call it grapefruit and it would still know that I mean a pixel?

A1:  No bad questions here! Please ask any and all questions! We named pixel as pixel. You could name it grapefruit (although that wouldn’t be a descriptive name)


Q: What is the difference between return and print?

A1:  Print “returns” information to the user in the terminal. Return literally returns information to the caller function (nothing is “returned” to the user)


Q: sSo are for loops and for each loops the exact same thing?

A1:  There are some difference between for range loops and for each loops. Once we go over for range loops we’ll highlight the differences


Q: What exactly does the image = SimpleImage(filename) line do? Thanks!

A1:  This create space in memory for the image that is store at the filename and stores it in a variable so you can access it (similar to bit = Bit(filename))


Q: So I know that you have said that for bit homework problems we have to stick to what's on the bit reference sheet. Can we use while loops? It doesn't appear to be listed on the sheet.

A1:  Yes you can use while loops! Thanks for checking! You can use anything from the bit lectures 1-3


Q: Will the tests be taken on our own or will we log into a lecture and do it then?

A1:  You will take them on your own using a software called Bluebook (more details will be released closer to the date). You will not log onto a Zoom


Q: Just for clarification, the hw instructions state that we shouldn't use for loops and other python features we have not covered yet. Since we learned for loops today may we use them in Homework 1 or should we stick to bit commands, while loops and if statements?

A1:  You cannot use for loops or variables. You can only use material from the bit lectures (1 - 3)


Q: In python can we write x += 1 instead of x = x + 1 ?

A1:  yes!


Q: Can we use the ‘+=‘ keyword?

A1:  yes!


Q: is it ok to write pixel.red = pixel.red >> 1

A1:  This functionally works but it is more clear to use pixel.red /= 2 (for people reading this who are unfamiliar, this is an advanced topic not covered in this class using binary numbers and bit shifting)


Q: After we change the pixel values how do we show the whole new image?

A1:  On the experiemental server, when you run your code it will update it (like Juliette is doing now).


Q: I didn't understand the answer to the question mentioned above that naming pixel as grapefruit would return pixel. Can you please explain again?

A1:  Yes! Thanks for following up! As a programmer, you decide what names to use for your variables. You can name your variables anything. For example, when we open the image we don’t have to call it image, you could call it image, blank_image, pizza, flower etc. But then everytime you want to reference the image (like to access the pixels) you have to use the exact name that you used to name it. It is good style to use descriptive names such as image to name an image instead of pizza. It is the same for pixels. In the for each loop (for pixel in image) pixel is a variable name. You could say for grapefruit in image, for pizza in image, for p in image etc. Please follow up if you still have questions!


Q: How do we know the size of the coordinate system? Is it given?

A1:  You can access the size of the image using image.width or image.height. The size of the coordinage system (i.e. the image) will vary and you want to write generally solutions that are no based on hard coded numbers


Q: What does she mean by “loop over all the coordinates”?

A1:  The coordinates are the height and width of the image and then each pixel has a coordinate like (3, 5).

A2:  An important note is that images are 0 indexed so we generally loop over the image.width - 1 or image.height - 1


Q: May I know where can we find the videos for our previous lectures?

A1:  Yes! On Canvas, click on the CS106A course and then on the sidebar click Panopto Course Videos


Q: Are these for-range loops like enhanced for loops?

A1:  For range loops tend to be more complex/give the user more flexiblity/funcitonality then a for each loop. But both for loops types are frequently used when programming.


Q: Follow up to the last question. I understand what the coordinates are, but what does she mean by “loop”? Is that the for loop?

A1:  Yes the for range loop.


Q: Does it automatically go to a new line or do we need to use an “endl” or “\n” when printing

A1:  Yes, it will automatically go to a new line (For others reading, other programming languages do not automatically hit “enter/return” to start a new line)


Q: What would you do if you wanted the for loop to start at a different number other than 0?

A1:  You can add another parameter: for i in range (start value, exclusive end value). So for example, for i in range (2, 6) would go to 2, 3, 4, and 5


Q: how to set a starting index for x other than 0

A1:  You can add another parameter: for i in range (start value, exclusive end value). So for example, for i in range (2, 6) would go to 2, 3, 4, and 5


Q: do we have anything to do tomorrow?

A1:  You have the day off unless you have section


Q: whats the homework gonna look like for this or is it just what we already have

A1:  You’re going to manipulate images!


Q: When will there be quizzes? Will there be a quiz tomorrow?

A1:  Friday wk 3 and Friday wk 7. No quiz tomorrow


Q: How do we submit homework?

A1:  Instructions will be posted at the bottom of the homework assignment handout later today


Q: When are we having our first quiz ?

A1:  Friday wk 3


Q: are if statements allowed on the HW?

A1:  Yes! if statements are allowed on the bit homework


Q: what’s the scheudle for LaIR?

A1:  Monday/Weds 5-7 and Tues/Thurs 7-9


Q: where are the section zoom codes

A1:  You can find your section zoom link on Paperless


Q: paperless?

A1:  https://paperless.stanford.edu/

A2:  This is where you will turn in homework, where you will see feedback on your assignments, where you will sign up for one-on-one IGs (interactive grading sessions). Your section leader will explain this in section


Q: how do you submit using paperless?

A1:  Instructions will be at the bottom of each assignment handout