Lecture Materials


Class Announcements

  1. Assignment 1 will be released after lecture today.
  2. Section signups: The section signup form will close today at 5pm. Please sign up for a section before 5pm today.

Questions & Answers


Q: Where can we access the session reccordings on canvas?

A1:  On Canvas, click the course CS106A -> on the sidebar select Panopto Course Videos.


Q: What's the purpose of the "bit = Bit(filename)" line?

A1:  This line creates space for bit in memory. You don’t need to worry about this line but know that it needs to be there to “initialize” Bit.


Q: Which part of the line “all_blue(filename)” is a name that we can change freely? Can we change “filename” into something else?

A1:  I’m assuming you’re talking about the line def all_blue(filename), if not, let me know. This line is the function definition line. The “all_blue” is the function name and “filename” is the name of the parameter (lots of this is material that will be covered later so don’t be overwhelmed if this answer is too technical). Both of these can technically be changed but then you would have to change every instance of these names. For example, if you changed filename to pizza you would have to put pizza in every spot where filename exists. But that would not be good style because pizza is not a descriptive name.


Q: Can bit also turn left? Or only right?

A1:  Bit can turn left and right :) bit.left() or bit.right()


Q: Do we end up writing our own custom attributes for the Bit class?

A1:  I believe no. But you will solve some puzzles with bit!


Q: what do you do if you want the bit to move only when the statement is flase?

A1:  You can use the not keyword. while not bit.front_clear()


Q: Can you please explain the error related to waggle dance?

A1:  Yes! This is an infinite loop error. While loops will continue to run until the condition is false. The way that the loop was originally written, the condition will never be false so the loop will never end

A2:  Since we never moved bit forward in the loop body, the loop was never exited. (Turning right and then left is like doing nothing since they “undo” each other)


Q: is it possible to paint a square "None"?

A1:  Nope. If you put “bit.paint(None)”, the computer returns an error.


Q: Is “none” in python equivalent to “null” in other languages?

A1:  Yep


Q: Seems like while and if are pretty similar. What is the difference between them?

A1:  While is a loop and if is a statement. A while loop will run until the condition is no longer true. An if statement will only run once.


Q: If the if statement is inside of the while loop will it run as long as the while loop is true?

A1:  If an if statement is inside of a while loop, the if statement will only run if the while loop condition is true AND the if statement condition is also true.


Q: If you can’t paint a block none, can you unpaint?

A1:  mmmm good question! I don’t think you can unpaint a square but you can paint a square a different color say from blue to red

A2:  Actually it looks like you can use bit.erase() to remove any paint


Q: Hello! I was wondering if there is a for loop in python?

A1:  Yes there is! Will will be learning about two types of for loops soon


Q: Please run error related to waggle dance?

A1:  We can’t go back but if you copy the code for the waggle dance into all_blue you can visiually see the error which might help understand. You can also follow up with some questions or stop by office hours! We’re super happy to help you understand this error!


Q: How do you create the “start” mode - like how is the world already a pre-determined size and how does each square already have a color set there? Do you code that yourslef or does the Bit program automatically have it there for you? Thanks!

A1:  This is all preset for you. Someone else did the coding for us!


Q: We can use if statement up to red square.

A1:  An if statement only runs once. Can you think of something else to use to run the code multiple times?


Q: How would one check for two separate conditions in any loop for Python? For example, how would one construct an if statement, given Condition A must be false and Condition B must be true?

A1:  Soon we’ll learn about using and and not. If you wanted to run an if statement if A is false and B is true then you could do “if not A and B:”. But we’ll go over this in much more detail in lecture soon!


Q: Looks like there isn't a main method in python. Does the first function run as the main?

A1:  Python does have a main function. We don’t use main on the experimental server but when we start coding using Pycharm there will be a main function.


Q: Is passing a variable to a function in python like passing variables to a template function in C++? Where it doesn’t matter what you pass as long as it doesn’t generate any error in the function

A1:  I’m not familiar with template functions in C++ but variables aren’t explicitly typed in Python. x can equal int 5 and then string “five” without any issue.


Q: Are there multiple ways to solve these bit problems?

A1:  Yes :)


Q: when is office hours

A1:  You can find the office hours on the course website https://web.stanford.edu/class/cs106a-8/ Juliette’s office hours are Tu/Th 9-10:30am PST, Tara’s office hours haven’t been announced yet, and LaIR (office hours with section leaders to get help with your code) is MW 5-7pm PST and Tu/TH 7-9pm PST I believe


Q: is there a bit.top_clear() and bit.bottom_clear() ?

A1:  There is bit.front_clear(), bit.left_clear() (similar to top clear), and bit.right_clear() (similar to bottom clear)


Q: Is there a way to do bit.get_color for the space to bit’s front/left/right

A1:  You can only call bit.get_color() for the square that bit is standing on


Q: Can you go over when to put a colon and when not to?

A1:  Yes! You want to put a colon at the end of function definitions, while loops, for loops (learning soon!), and if statements. Basically anytime you need to indent your code put a colon


Q: is there a list/dictionary of commands to use with bit?

A1:  No. Bit cannot use variables.


Q: How do we access the homework?

A1:  It will be posted on the class website under the assignments tab later today


Q: When will everyone's section times be announced?

A1:  Tonight or tomorrow morning


Q: Are there time limits for these bit problems?

A1:  No time limits for the homework (except for completing it before the due date). You will have to do these in a timed settng on the quiz at the end of week three but that is after a lot of practice :)


Q: Is the assignment on the website?

A1:  It will be posted after lecture today


Q: How do we review this Q&A after the chat is over?

A1:  We can post them if that would be helpful :)


Q: what will be doing in sections

A1:  Working through practice problems as a small group.


Q: what link do we use for the office hours timings? Is it this same zoom link

A1:  https://web.stanford.edu/class/cs106a-8/restrictedSum/zoominfo.html


Q: Can you explain go east?

A1:  We will explain this in more detail tomorrow :)


Q: what this def all about and every code we start with some initial file name, what that is all about ?

A1:  def is the keyword for defining a function