Lecture Materials


Class Announcements

  1. Assignment 1 will be released today.
  2. Section signups: The section signup form will open tomorrow at 5pm. You can find it as an announcement on the course webpage. Sign up before Sunday at 5pm.

Questions & Answers


Q: Is there a way to “submit” the assignment?

A1:  01/05/2022 14:32:12

A2:  Not yet. There is a second part coming out Friday and then we will post submission instructions over the weekend.

A3:  01/05/2022 14:33:46


Q: can we do the assignment if we're not yet enrolled in the class?

A1:  01/05/2022 14:33:05

A2:  01/05/2022 14:33:23

A3:  You can do it, but you won’t be able to turn it in.


Q: nick’s screen is just black. I don’t know if this is just a me issue though

A1:  01/05/2022 14:33:58

A2:  It is like that for everyone. Maybe it will fix soon.

A3:  01/05/2022 14:33:31


Q: If we make mistakes on the homework assignment, do we lose partial points?

A1:  Yes.

A2:  01/05/2022 14:34:26

A3:  01/05/2022 14:35:54


Q: Why Bit starting point is at the left upper corner all the time?

A1:  Sometimes bit will start in different places.

A2:  01/05/2022 14:36:09

A3:  01/05/2022 14:35:17


Q: What does the # do? Is it an actual command?

A1:  01/05/2022 14:38:53

A2:  That tells the computer to ignore everything after it on that line. It is how programmers write comments to ourselves.

A3:  01/05/2022 14:37:49


Q: is the text in green supposed to be there as code?

A1:  01/05/2022 14:38:20

A2:  01/05/2022 14:39:14

A3:  That is what we call a comment. It is a way to write info to yourself and anyone reading your code. The # tells the computer to ignore it.


Q: are we supposed to use the “practice mode” to avoid losing points on incorrect submissions? I was testing my code w/out enabling the setting bc I didn’t realize that running incorrect code as a test would result in the loss of points also, is there anywhere we can see documentation? it’s somewhat difficult to remember all the functions available to us

A1:  01/05/2022 14:42:06

A2:  01/05/2022 14:38:35

A3:  There is a bit reference guide on the website (under the resources tab). Practice mode just resets the code to what it was before (if you have already solved it). Students mostly use it when studying for exams.


Q: How can i see line numbers on my screen?

A1:  01/05/2022 14:43:27

A2:  01/05/2022 14:39:26

A3:  There is a box you can check at the bottom of the screen.


Q: why there are spaces in front of bit. move() and bit.paint ('blue') on line 5&6?

A1:  The indentation means lines are inside the while loop (so they will repeat with the while loop)

A2:  01/05/2022 14:40:58

A3:  01/05/2022 14:43:18


Q: Does def just mean define a function? If so, does the function run automatically when it is defined? You don't have to call it after?

A1:  01/05/2022 14:41:32

A2:  01/05/2022 14:45:01

A3:  def defines a function. You do have to call it which is what happens when you click run. You can checkout the box next to the run button which has the name of the function that is called when we hit the run button.


Q: What “Diff” box does?

A1:  That tells you what is different between your output and the solution output.

A2:  01/05/2022 14:45:20

A3:  01/05/2022 14:41:52


Q: Do we lose points if we have errors in our code when we are still testing, or only if there are still errors once we submit?

A1:  01/05/2022 14:45:28

A2:  01/05/2022 14:43:43

A3:  We only grade what you submit


Q: where can I find this note?

A1:  01/05/2022 14:44:26

A2:  01/05/2022 14:45:42

A3:  Course webpage -> lectures -> 2. Control Flow


Q: why do you have to check your code on all cases?

A1:  We want to write code that is general to work in all worlds.

A2:  01/05/2022 14:44:29

A3:  01/05/2022 14:45:53


Q: in this one there are no hashtags. are hashtags just to keep track of what you are doing for commentary?

A1:  01/05/2022 14:44:44

A2:  Yes! Comments are for programmers to keep track of what they are doing and also to help anyone reading their code understand what is happening.

A3:  01/05/2022 14:46:14


Q: does running incorrect code as a test without submitting it result in a loss of points?

A1:  Nope. We only grade what is submitted.

A2:  01/05/2022 14:46:23

A3:  01/05/2022 14:45:06


Q: why dont you have to test if the first square is clear?

A1:  01/05/2022 14:47:17

A2:  Can you elaborate on this?

A3:  01/05/2022 14:46:39


Q: What does the “in class vote” button do?

A1:  01/05/2022 14:47:23

A2:  No idea. I don’t have that on my end :/

A3:  01/05/2022 14:49:22


Q: The bit can’t move downwards?

A1:  Bit always moves in the direction it is facing. Does this help clarify?

A2:  01/05/2022 14:48:29

A3:  01/05/2022 14:49:05


Q: to elaborate: the while loop tests if the second square is clear and then decides to paint it blue if it is clear. but i dont see where that happens for the first square?

A1:  01/05/2022 14:48:44

A2:  If bit is on a square, it must be clear. We just need to check if any squares we are moving to are clear. Does this help clarify?

A3:  01/05/2022 14:50:02


Q: How do you know the direction in which the bit is facing?

A1:  It is kind of tricky, but you can look at the legs. bit is facing to the right when there is one leg on the bottom and one leg on the left. As you work more with bit, it will be easier to tell.

A2:  01/05/2022 14:49:27

A3:  01/05/2022 14:50:45


Q: to submit the homework, is there anything special we have to do? or can we just leave it on the website completed

A1:  01/05/2022 14:50:59

A2:  There is a special way to do it. We will announce instructions over the weekend.

A3:  01/05/2022 14:49:29


Q: I feel like there is so much we are skipping in this lecture that i dont know

A1:  01/05/2022 14:51:10

A2:  Can you give an example?

A3:  01/05/2022 14:49:41


Q: so there’s no syntax required to close the loop? indentation is enough in python to achieve that?

A1:  01/05/2022 14:51:19

A2:  Yes. Exactly.

A3:  01/05/2022 14:49:51


Q: yes thank you!

A1:  01/05/2022 14:50:30

A2:  01/05/2022 14:51:22

A3:  :)


Q: When you click “in class vote”, you can then choose if you understand the solution or not.

A1:  01/05/2022 14:50:34


Q: Do you have to memorize code format?

A1:  01/05/2022 14:52:03

A2:  Some of the format you will have to memorize (when to indent, how to write an if statement etc). But you do not need to memorize specific functions. You can check out the bit reference guide to see all of the bit features.

A3:  01/05/2022 14:53:15


Q: if there is only four columns, will it still show up as error?

A1:  01/05/2022 14:52:32

A2:  You can test it out!

A3:  01/05/2022 14:52:18


Q: Will we have to write the first 2 lines of the code on our hw or will that be given?

A1:  01/05/2022 14:53:18

A2:  01/05/2022 14:55:54

A3:  It will be given.


Q: Where is the bit reference guide?

A1:  01/05/2022 14:53:34

A2:  Under the resources section on the home page of the course website.

A3:  01/05/2022 14:56:09


Q: Where is the bit reference guide?

A1:  01/05/2022 14:56:11

A2:  01/05/2022 14:53:49

A3:  Under the resources section on the home page of the course website.


Q: How does the 5% Section grading work for SCPD students?

A1:  You will attend an SCPD specific section that is virtual all quarter.

A2:  01/05/2022 14:56:27

A3:  01/05/2022 14:55:15


Q: How does the computer instantly know the loop is infinite versus a very long instance of the loop that will eventually resolve?

A1:  Python is super fast (even for really really long loops). So the computer has a timer and if a loop takes more than one second (for Bit) there must be an infinite loop. In python outside of bit, you do not get this nice error message. Come chat at office hours if you want to hear more about this.

A2:  01/05/2022 14:55:31

A3:  01/05/2022 14:57:59


Q: Why would it loop infinitely instead of just crack?

A1:  If the while expression is never false, it will get stuck inside that loop.

A2:  01/05/2022 14:55:35

A3:  01/05/2022 14:58:22


Q: when the syntax is wrong, does the program just not register it as a command and skip over it?

A1:  01/05/2022 14:59:20

A2:  01/05/2022 14:55:56

A3:  For most syntax errors, the program will error instead of running. Forgetting parens is a specific kind of error where the command does get skipped over. But with other syntax errors, the program won’t run at all.


Q: Why does the lack of parentheses cause an infinite loop error rather than a syntax error for like the example from last class?

A1:  Forgetting the () is not quite a syntax error in the same way as adding an extra parens, or spelling something wrong. This is something we will explain much later in the quarter, but in short bit.move without the parens tricks the computer into thinking it is a command that does nothing. So the program doesn’t think it is a syntax error (causing an infinite loop) instead of the syntax error we saw last class.

A2:  01/05/2022 15:01:57

A3:  01/05/2022 14:56:02


Q: can you use infinite loop to your advantage if you actually wanted the code to run forever?

A1:  01/05/2022 15:02:13

A2:  01/05/2022 14:56:20

A3:  In theory


Q: why didnt the bit.move with no parentheses have no error message?

A1:  See above answer about bit.move as a syntax error. Follow up if I can further clarify.

A2:  01/05/2022 15:02:36

A3:  01/05/2022 14:56:24


Q: why program still running instead of giving syntax error without `()`

A1:  See above answer about bit.move. Follow up if I can further clarify.

A2:  01/05/2022 14:56:27

A3:  01/05/2022 15:02:52


Q: is there a place where we can find this lecture document or just follow via the experimental tab?

A1:  Course webpage (cs106a.stanford.edu) -> lectures -> 2. Control Flow -> Lecture notes

A2:  01/05/2022 14:56:29

A3:  01/05/2022 15:03:13


Q: Is this course all virtual?

A1:  01/05/2022 15:03:32

A2:  We are hoping to be in person soon. Even when we are in person, lectures will still be recorded.

A3:  01/05/2022 14:57:34


Q: could the timing for the SCPD specific section be outside of work hours?

A1:  01/05/2022 15:03:50

A2:  I think there will be a few times to choose from.

A3:  01/05/2022 14:57:49


Q: Is it possible to do a while bit.get color ?

A1:  you could do: while bit.get_color() == ‘red’: or something like that

A2:  01/05/2022 14:59:15

A3:  01/05/2022 15:04:18


Q: What does it mean when the homework says we should only use "one function" to solve it?

A1:  01/05/2022 15:04:51

A2:  01/05/2022 15:00:07

A3:  On friday, we will learn how to use more than one function to solve problems. So the early ones want you to only use what you know now to solve it.


Q: What if you put a color in the parentheses for bit.get_color--for example bit.get_color('red')?

A1:  That will cause an error.

A2:  01/05/2022 15:05:00

A3:  01/05/2022 15:00:43


Q: what does get color mean

A1:  01/05/2022 15:05:13

A2:  01/05/2022 15:00:49

A3:  That give you back the color of the square on which bit is standing.


Q: Is Python always case sensitive?

A1:  yep

A2:  01/05/2022 15:00:56

A3:  01/05/2022 15:05:17


Q: Is the syntax for None, ‘none’ or is it None?

A1:  None (not in quotes with a capital N)

A2:  01/05/2022 15:05:26

A3:  01/05/2022 15:01:10


Q: How can students save progress and work when completing the Bit assignments to submit?

A1:  01/05/2022 15:05:45

A2:  Your progress is saved everytime you hit run.

A3:  01/05/2022 15:01:44


Q: if None is False always?

A1:  None is False always.

A2:  01/05/2022 15:05:54

A3:  01/05/2022 15:02:16


Q: For example, if you want bit to move until you get a color, is it possible to do a while bit is get color green move?

A1:  01/05/2022 15:05:59

A2:  Yes.

A3:  01/05/2022 15:03:23


Q: Why is it called ‘bit.get_color()’ and not just bit

A1:  01/05/2022 15:06:09

A2:  Can you elaborate on this?

A3:  01/05/2022 15:04:01


Q: What if the first square is blue ? should we but if before move

A1:  You can test it out !

A2:  01/05/2022 15:06:19

A3:  01/05/2022 15:04:14


Q: How do we turn in the homeowrk after we complete it?

A1:  01/05/2022 15:04:55

A2:  We will release instructions for turning in HW over the weekend.

A3:  01/05/2022 15:06:31


Q: Is there a way to do an if statement for say more than one color? For example, if the square was red or blue?

A1:  01/05/2022 15:05:20

A2:  01/05/2022 15:06:48

A3:  It is possible, but we have not learned it yet.


Q: what would occur if uou put “=!” instead

A1:  01/05/2022 15:07:17

A2:  That gives a syntax error

A3:  01/05/2022 15:05:25


Q: Is there a way to say if the square equals 2 different colors?

A1:  yes, but we have not learned this yet. Try to solve without doing this for now.

A2:  01/05/2022 15:08:04

A3:  01/05/2022 15:05:32


Q: I was looking at the above questions… what does SCPD stand for?

A1:  Stanford Center for Professional Development. It is a way for people who are not students at Stanford to take a few Stanford courses.

A2:  01/05/2022 15:05:51

A3:  01/05/2022 15:07:46


Q: what does boulean test mean?

A1:  A boolean is a fancy way of something “a thing that will either be true or false.” When you use == or != that will evalute to a boolean. Either the two things are equal, resulting in True or the two things are not equal resulting in False (and vice versa for !=). So an if statement or a while loop both use boolean tests to see if we should do the code inside those statements. Does this help clarify? Please follow up if not.

A2:  01/05/2022 15:11:10

A3:  01/05/2022 15:08:58


Q: on the cave blue homework, there seems to be a “show solution” button, if we click that, will we receive less credit on the homework, or is it allowed?

A1:  01/05/2022 15:09:47

A2:  Thank you for letting us know. For now don’t click it. More info to come.

A3:  01/05/2022 15:17:46


Q: when is a while loop preferable to an if loop?

A1:  01/05/2022 15:09:55

A2:  A while loop repeats multiple times, an if statement is not a loop. It just happens once.

A3:  01/05/2022 15:11:45


Q: Thank you! I am having trouble locating the tab. I only see the lecture link to zoom.

A1:  01/05/2022 15:10:03

A2:  01/05/2022 15:12:29

A3:  https://web.stanford.edu/class/cs106a/ At the very top there is a drop down menu called “Lectures”. Lmk if you don’t see it.


Q: Could he have used == none

A1:  01/05/2022 15:10:50


Q: how to distinguish the end of IF statement and the next line code?

A1:  Indentation. Anything indented under the if is part of that if statement.

A2:  01/05/2022 15:12:50

A3:  01/05/2022 15:10:51


Q: Why do we put the color in the parentheses but not things like !=

A1:  01/05/2022 15:11:14

A2:  01/05/2022 15:13:42

A3:  when you say bit.paint(‘red’) we put the ‘red’ inside the parens to tell bit what color to paint that square. This is because the paint function needs a bit of extra info in order to work properly.


Q: Wait I'm still confused, why wouldn't bit stop at the first green block?

A1:  01/05/2022 15:12:29


Q: Why did the code he just ran paint those two green squares red?

A1:  01/05/2022 15:12:52

A2:  Bit paints the squares red before checking if the one it is on is green.

A3:  01/05/2022 15:16:09


Q: Why does one need to indent?

A1:  Indentation in python is how programmers indicate which lines should happen inside while loops, if statements, functions and what lines should happen outside of those.

A2:  01/05/2022 15:14:31

A3:  01/05/2022 15:13:03


Q: still dont understand why the previous code (without if…== None) does not work:)

A1:  Try going through it with the step button on the experimental server to see why bit doesn’t stop.

A2:  01/05/2022 15:14:13

A3:  01/05/2022 15:15:03


Q: To clarify - it is okay to work on homework part A, clicking run to test whether our code is correct, and this will not “submit” the assignment, correct?

A1:  01/05/2022 15:16:22

A2:  Correct.

A3:  01/05/2022 15:15:02


Q: Can you invert a bit.front_clear line with an “!” as well?

A1:  01/05/2022 15:19:59

A2:  Better to use not like Nick is explaining.

A3:  01/05/2022 15:15:07

A4:  Yes !

A5:  01/05/2022 15:16:17


Q: for the homework, after we successfully complete a coding excercise, how to we submit it?

A1:  01/05/2022 15:17:00

A2:  01/05/2022 15:18:00

A3:  Instructions for submission will come out this weekend.


Q: OHhhhhh it makes sense now hahahah

A1:  01/05/2022 15:17:04


Q: To invert bit.front_clear where would you place the “!”?

A1:  while !bit.front_clear():

A2:  Better to use not. while not bit.front_clear()

A3:  01/05/2022 15:18:13

A4:  01/05/2022 15:20:14

A5:  01/05/2022 15:17:36


Q: Thank you so much :)

A1:  01/05/2022 15:18:00


Q: how to sign up for Thuesday practicing session? Can I sign up it for no credit?

A1:  Section signups open tomorrow. They are part of your attedance score. If you are not enrolled, please do not sign up for a discussion section.

A2:  01/05/2022 15:19:38

A3:  01/05/2022 15:20:47


Q: can you clarify what a boolean is?

A1:  It is something that can either be true or false.

A2:  01/05/2022 15:19:50

A3:  01/05/2022 15:21:00


Q: Isn’t using “if not…” the same as using “if … !=…”?

A1:  01/05/2022 15:22:07

A2:  We use not before things like bit.front_clear() and bit.right_clear() and we use ! when checking if two things are not equal (while bit.get_color() != ‘red’).

A3:  01/05/2022 15:20:18


Q: Is "not" infornt of the else condition the same as using an elsif statement?

A1:  Not quite.

A2:  01/05/2022 15:20:58

A3:  01/05/2022 15:22:18


Q: is there a glossary of all the python words/syntax somewhere?

A1:  01/05/2022 15:22:42

A2:  You can find the bit reference and python guide under the resources section on the main page of the course website.

A3:  01/05/2022 15:23:22


Q: what does test=Go mean?

A1:  01/05/2022 15:23:30

A2:  01/05/2022 15:24:12

A3:  Where does it say that


Q: where do we code this?

A1:  On the experimental server. The link is on the lecture notes for today

A2:  01/05/2022 15:24:56

A3:  01/05/2022 15:24:31


Q: What are we doing right now for a minute?

A1:  01/05/2022 15:24:40

A2:  Coding an example on the experimental server

A3:  01/05/2022 15:25:05


Q: Where is the experimental server

A1:  01/05/2022 15:25:33

A2:  01/05/2022 15:27:06

A3:  It is linked from the course notes. Also here: https://wopr-service-qbrbcbuzwa-uw.a.run.app/


Q: what's the target image for the "standard coyote"?

A1:  You can put the solution code in it and run that to check

A2:  01/05/2022 15:26:01

A3:  01/05/2022 15:27:21


Q: my application doesn’t show the picture before I start

A1:  01/05/2022 15:26:04

A2:  01/05/2022 15:28:56

A3:  on the experimental server?


Q: how do I access the lecture notes

A1:  01/05/2022 15:26:27

A2:  01/05/2022 15:27:58

A3:  From the course website (cs106a.stanford.edu) click the Lectures drop down menu, select 2. Control Flow, and then click lecture notes.


Q: It says “Test = Go” in the lecture notes where it says “Reverse Coyote, remember Test = Go”

A1:  Ah yess. The test for an if statement or a while loop determines if we ‘go’ into those lines of code.

A2:  01/05/2022 15:28:31

A3:  01/05/2022 15:27:14


Q: I can’t see the case it is just blank white

A1:  when you run your code or the solution code?

A2:  01/05/2022 15:28:32

A3:  01/05/2022 15:28:47


Q: if you run the homework code with practice mode off, does that submit it, or is there a separate submit button?

A1:  01/05/2022 15:29:07

A2:  01/05/2022 15:28:56

A3:  There is a separate submission button.


Q: why would you use not left_clear() here instead of right_clear? also, why use right_clear() instead of front_clear? they do the same thing for me

A1:  left_clear() is not a command that bit knows. front_clear() and right_clear() are slightly different. front checks what is right in front of bit and right checks what is directly to the right of bit.

A2:  01/05/2022 15:29:19

A3:  01/05/2022 15:32:10


Q: follow up question: where is the submission button?

A1:  does not exist yet.

A2:  01/05/2022 15:31:48

A3:  01/05/2022 15:32:17


Q: Is it considered an error (for homework purposes) when bit hits a wall at the end of a loop and it returns the error saying it can’t move forward?

A1:  01/05/2022 15:32:23

A2:  yes

A3:  01/05/2022 15:31:56


Q: do we sign up for sections now?

A1:  01/05/2022 15:32:02

A2:  01/05/2022 15:32:38

A3:  Section signups come out tomorrow at 5pm.


Q: what was that last thing you said about 5pm?

A1:  01/05/2022 15:32:15

A2:  01/05/2022 15:32:40

A3:  Section signups come out tomorrow at 5pm.


Q: do we need to finish all the practice in notes?

A1:  01/05/2022 15:32:48

A2:  That practice is just for you

A3:  01/05/2022 15:32:17


Q: Thank you!

A1:  01/05/2022 15:32:23


Q: sorry, where can i find the lecture notes?

A1:  01/05/2022 15:32:56