Lecture Materials

Class Announcements

We've posted information about the diagnostic and some practice material on this handout. Please make sure to have downloaded and installed BlueBook, our exam platform.

Questions & Answers


Q: are we supposed to be able to tackle problems like the calendar problem Chris did on Wednesday?

A1:  Not right now. But by the end of the quarter you will be able to! Try to work through it and understand how Chris tackled it.


Q: When I tried to submit assignment 2 it said my files were invalid. What should I do?

A1:  Are you submitting your .py files? Try uploading again. You can also email your section leader for help!


Q: Is there diagnostic practice somewhere?

A1:  Yes! Posted on the website.


Q: what will the structure of the diagnostic be? would it be like a short version of the pset?

A1:  It will be like the practice diagnostic structure!


Q: will we be able to run our code for the diagnostic?

A1:  Yes, but read the diagnostic handout to learn more about this.


Q: are we supposed to turn in sandcastles to be graded or are they just for us to practice?

A1:  You turn them in for a grade.


Q: How to get notified when something is posted on course website?

A1:  I am not sure there is a way to do that.


Q: will there be karel on the exam?

A1:  Yes!


Q: Are our functionality and style grades averaged for each assignment?

A1:  Assignments make up 70% of your grade. They are weighted more towards the assignments at the end of the quarter.


Q: How many questions is the test and will it only take 1 hour long?

A1:  It is only 1 hour. Check out the practice diagnostic.


Q: Sorry, so is our grade for each assignment an average of the functionality grade and the style grade? Or does the functionality grade count more than the style grade?

A1:  In the first assignments, functionality is weighted more heavily.


Q: Should you always write constants outside of a function?

A1:  Yes.


Q: I am using one of the five extension days for this past assignment, but the LAIR hours aren’t open today. What should I do?

A1:  There are only four free late days. Try looking at posts on Ed to see if anyone had a simliar problem. You can also try tracing through each line of your program to understand where there might be a bug.


Q: is using break at the end of a loop bad style?

A1:  No this is not bad style. Sometimes it is useful!


Q: Can there be constants within a function?

A1:  If you define constants in a function, then they are not available to all functions in the program. You should define constants outside of a function.


Q: Is a global constant fine?

A1:  Yes.


Q: How is the diagnostic graded? Letter or check system? Is there a curve?

A1:  Mehran and Chris will give more information about this.


Q: My stanford email is invalid of Ed, is there anyother way to sign up with like a link

A1:  Email Juliette about this.


Q: Will the diagnostic be open note?

A1:  Yes. Read the diagnostic for more information about the open note policy.


Q: if the ‘amount’ variable only valid inside the while loop? what if I use it outside while loop, would it be a separate variable?

A1:  You can use the amount variable at any point inside main after you first assign it. It will be the same variable all throughout main.


Q: so when using parameters we can pass two or more variables? could we do that on assignment 2?

A1:  Yes you can pass as many variables as you think necessary, and yes you can use this on assignment two.


Q: why is it useful to create the main function? instead of just writing directly the code?

A1:  This keeps our code more organized and makes it clear which functions get called when a program is run.


Q: How long do I have to make up the assignment for a late day? Will my grade be lowered?

A1:  Everyone has 4 free late days. Each late day is a 24 hour extension on an assignment. You can use a late day without being penalized. If you want to use one late day on assignment two you must turn it in by 1pm on Saturday 10/3. 2 late days and you have until Sunday 10/4.


Q: what is the difference between break and just putting return there in this instance?

A1:  There is no difference in this specific example. In other examples, you may break out of a while loop and then do more computations below the while loop.


Q: What does the “True” in the while loop refer to?

A1:  A while loop will repreat so long as the condition is True. Here, instead of giving a condition, we are just writing True, so this function should always repeat. We are saying that this loop should continue forever (until we reach the break inside the code).


Q: Are the functionality and style grades averaged for each individual assignment?

A1:  Yes but functionality is more heavily weighted.


Q: More of a specific question, but in one of my programs I wanted to get a user input from the user and assign it to a variable, but never change that variable again in the program (It becomes like a constant). That variable was used in many functions throughout the program. In that case is it okay to declare global?

A1:  We do not want you declaring any variable global. In that case, it would have been better to ask for user input at the top of the main function as pass it to other functions if you need to.


Q: Is "break" considered to be good style?

A1:  It can be good style.


Q: is there a way to pass in a set of parameters instead of having to do them all individually?

A1:  We will learn more about this later in the quarter.


Q: what does while true in this code mean? while what is true?

A1:  A while loop will repreat so long as the condition is True. Here, instead of giving a condition, we are just writing True, so this function should always repeat. We are saying that this loop should continue forever (until we reach the break inside the code).


Q: What does 0 to quit mean?

A1:  If the user types 0, the while loop should stop repeating.


Q: Are arguments found in main and parameters in helper functions? If not, what is the difference?

A1:  When you define a function, you call them parameters. When you pass values into a function you call them arguments. So in the caller function, you call them arguments. In the callee function they are called parameters.


Q: will we always have IG for assignments?

A1:  yes.


Q: What does break do ?

A1:  Break ends the while loop even if the condition is still true.


Q: How similar is the level of difficulty of the practice diagonistic compared to the actual one?

A1:  Relatively the same.


Q: what exactly does stack frame refer to? Is it each function “card”?

A1:  Yes!


Q: I’m confused what the while True statement in this specific code means. What makes the loop true?

A1:  A while loop will repreat so long as the condition is True. Here, instead of giving a condition, we are just writing True, so this function should always repeat. We are saying that this loop should continue forever (until we reach the break inside the code).


Q: Could we have chosen different argument/parameter names for deposit()? Right now, it also takes in ‘balance’ and ‘amount’, couldn’t they have different names? (E.g. ‘bal’, ‘amo’)

A1:  Yes.


Q: Are doctests fair game for the diagnostic?

A1:  Yes.


Q: Just to clarify, parameters are used so that variables can be used in multiple functions without needing a global variable?

A1:  Yes!


Q: what if you want to alter more than one variables in a function and the variables need to be used in several functions?

A1:  This is a difficult thing to do. You likley cannot decmopose into a helper function in this case.


Q: can we pass multiple variables all within one paramter? for example, if balance = deposit(balance, amount), could we theoretically have placed more than just those two variables (balance and amount) in the deposit function if needed

A1:  Not with what you know in this class so far. We will talk about this more later in the quarter.


Q: What distinguishes a helper function from a normal one?

A1:  We call any function that is not main a helper function.


Q: Getting this error for console: Error:Python interpreter is not selected. Please setup Python interpreter first.

A1:  Post on Ed about this.


Q: What does a check plus on functionality and check on style translate into as a letter grade?

A1:  They don’t directly translate. We say that students who excel in this class get mostly checks and check pluses on assignments.


Q: Are both functionality and style graded on the same ‘bucket scale’? Or, is there a maximum that can be achieved for functionality or style?

A1:  Functionality is weighted more heavily that style.


Q: what is point of console?

A1:  It is a way to run your python code without using pycharm.


Q: when you use commas instead of + in print, do you not need to use str() for variables?

A1:  Correct!


Q: Why would you need to use the console?

A1:  It is a way to run your python code without using pycharm.


Q: Do you have to type exit at the end of using the console or can you just exit?

A1:  you have to type exit. I think you can aslo do ctrl+d.


Q: In section, I couldn’t access EdStem because it said invalid email address, and it didn’t email me when I entered one to create an account. How do I create an account?

A1:  Email Juliette.


Q: is None like the null in Java?

A1:  Similar!


Q: Is it possible to get a + for style? If so, how does one do that?

A1:  This is not possible.


Q: if i were to type x = word and then asked for x, would it return “word” or None?

A1:  It would tell you that word is undefined. Unless you previously defined word. Try it out on the console yourself!


Q: how are extensions/optional problems graded? are they extra credit, or are they included in the grade for that assignment?

A1:  They are extra credit.


Q: So None is like undefined?

A1:  Similar!


Q: Are lists just the same thing as arrays?

A1:  Lists are similar to arraylists in Java.


Q: what can we do with the mixed type lisy? wont it be hard to use?

A1:  Yes. In practice you will mostly have lists of the same type. But you could come accross a mixed type list.


Q: what does the console do? im still kind of confused

A1:  It is a way to run your python code without using pycharm.


Q: Are lists another type?

A1:  Yes!


Q: does that mean 1 and 1.0 are not equal since they're different types?

A1:  try it out in the console!


Q: why is the console preferable to use over pycharm, if ever?

A1:  If you want to test things about python in the way Mehran did at the beginning of lecture!


Q: can you print lists and if so will it show each element printed out in order. also can you name lists anything like you can variables?

A1:  You can name lists anything you want. When you print a list it will print out each element in the order that it was in in the list.


Q: could by list contain boolean statements?

A1:  Yes! You can have a list like [True, False, False] or something like that.


Q: So is the list itself a variable as well that contains a bunch of other variables in it?

A1:  Yes!


Q: why start at 0?

A1:  That is just how programmers count.


Q: Why not start at 1?

A1:  That is just how programmers count.


Q: what does the i in the bracket represent

A1:  That represents the index of the element in the list.


Q: how do you know to use , or + when printing more than one element? or does it not matter

A1:  Can you elaborate on this?


Q: Would it be bad style to interate through the list with enumerate? “for i, element in enumerate(list)”

A1:  You can use enumerate.


Q: whats purpose of having -ve index?

A1:  In case you want to get things from the end of a list. Perhaps you always want the last value from a list. Instead of having to compute the length of the list and trying to do lst[len(lst)-1] you can just do lst[-1]


Q: is there a max number of elements we can contain in a list

A1:  You can include as many elements as your heart desires.


Q: I feel like I am watching this lecture on 1.5X the speed!! Can we move any slower? Or too much material today?

A1:  Lots of material to cover today. Try looking over the lecture again this afternoon.


Q: can you append multiple elements at the same time

A1:  live answered


Q: can you combine lists or append lists?

A1:  Yes. Extend will combine lists. You can also append a list so that the outer list will contain the list you just appended.


Q: does new_list always create an empty list or is it just the name of a list that was just made

A1:  That is just the name.


Q: can you compose different lists?

A1:  Can you elaborate on this?


Q: do you have to use a variable to remove an element from a list?

A1:  No you can just call lst.pop() without setting it equal to a variable. You would not have that last element stored anywhere.


Q: when we use .pop to remove an element of a list and define it as say “x”, can we add “x” to another list

A1:  Yes!


Q: What's the difference between the console and doctests?

A1:  Doctests are a way that you can test specific functions using specfic input values. The console is a way to run python that you are curious about!


Q: can you check for a list of values in another list?

A1:  live answered


Q: why is it c and not b?

A1:  List indices start at 0. So ‘a’ is at index 0, ‘b’ is at index 1 and ‘c’ is at index 2.


Q: Why would you do pop when you could just not include the variable in the list?

A1:  Perhaps you already created the list and only know that you want to remove it once something has happened.


Q: does the remove function return the value?

A1:  No, but you should already have the value in a variable because you are telling the function what to remove.


Q: Are lists read right to left?

A1:  Lists are read left to right.


Q: Can you add or remove more than one element with a single command? ex. fun_list.pop(2, 3)

A1:  I believe you can only remove one element at a time.


Q: does pop usually print out the element in the list it removed? or just modify the list

A1:  Pop removes the element and returns it. It does not print the value.


Q: Does it return the element or it's index?

A1:  Which function?


Q: I have a main function defines several variables, and 2 helper functions. The first helper calculates a new variable that is used in the second helper function. The second helper function also uses a variable defined in main that isn’t used in the first helper function. Is it better style to return this new variable in the main function and then pass it along to the second helper function? Or can I pass along the unused argument into the first helper function (even though it isn’t used within that function) in order to pass it along to the second helper function, which would be called at the end of the first helper function?

A1:  This may be better as an Ed post or an email to a section leader! You will get a better answer that way.


Q: what if your list is numbers that dont match your index, how would you specifiy whether youre naming an element or an index?

A1:  pop takes in an index, remove takes in an element.


Q: What grades should we maintain to ultimately get an A or A+?

A1:  We say that students who excel in this course are getting check pluses and checks on assignments.


Q: how does pop() remove elements from a list permanently and not just locally?

A1:  Mehran will talk more about lists and how they work across functions.


Q: Can you say list3 = list1.extend(list2) ?

A1:  Yes !!


Q: Can you append multiple elements at the same time?

A1:  You have to use extend to do this.


Q: What happens if you append a list to itself?

A1:  If you do: l1 = [a, b] l1 = l1.append(l1) Then l1 = [a, b, [a, b,]]


Q: so when you append two lists it places one list within another. but when you extend two lists, it merges two lists seamlessly?

A1:  Exactly !


Q: Is it possible to pop off all elements that are duplicative in a list?

A1:  You can write a program to do this!


Q: Follow up question: if you said list3 = list1.extend(list2), would it change list1?

A1:  Yes!


Q: So in python the objects arn't references, but like, the actual thing, does it make a copy of the elements when it inserts them?

A1:  Chris and Mehran will explain this in more detail in the next few lectures!


Q: are we expected to memorize ALL these functions?! a lot!

A1:  You do not need to memorize any functions! As you program, you will develop familiarity with these.


Q: what’s the maximum grade for style in assignments?

A1:  The maximum bucket for style is check plus.


Q: what happens if there are multiple of the same elements in a list and you ask for the index?

A1:  it will chose the first index where an element has the value that you passed into remove. You can try this out on the console!


Q: why was .copy() necessary? wouldn't the line fantasy = jedi work by itself

A1:  live answered


Q: If you just set one list equal to another, will they refer to the same group of things? (Like if I change the second list will that also change the first one?)

A1:  Yes. Mehran and Chris will talk more about this in the next few lectures.


Q: Instead of copy(), can we not just copy the list by doing copied_list = original_list ?

A1:  live answered


Q: could all these functions potentially be tested on the diagnostic?

A1:  Yes. The diagnostic is open note so you will not have to memorize them. And the diagnostic will priortize material covered earlier in the quarter. But you should be familiar with these functions.


Q: How much will we need to comment our functions in the diagnostic? Are there file headers to write for the diagnostic?

A1:  Read the diagnostic handout to see how we are going to evaluate your style on the diagnostic!


Q: If sum(list) of a list with strings return an error?

A1:  Yes.


Q: what happens is you take the sum of the list but theyre strings

A1:  You will get an error. Feel free to try it on your console!


Q: Is this str_list a subset of the supreme court justices?

A1:  You can make of the names what you will.


Q: Do you have to define elem before you use the for-each loop in the example?

A1:  No. The for loop defines elem as the first thing in the list. Similar to how for i in range defines i to be 0 at first.


Q: What should you calll the “elem” variable if you’re not planning on using it?

A1:  you can still call it elem.


Q: is it still possible to join the 1 unit helper class for cs106a if we are having trouble with the class material

A1:  Email sonjyu@stanford.edu and ask!


Q: If you made two assignments like x = 0, then x = x + 1, is the second line creating a new object or simply modifying the first one?

A1:  live answered


Q: So is a list a “global variable” of sorts?

A1:  Lists are a special type of variable that can be modified when passed amongst functions.


Q: wait so it changes in main even if we dont return the add five list?

A1:  Yes!


Q: so we need to use return for the other types but not for lists?

A1:  You can still return lists! But just know that changes you make to list in a function can persist without returning.


Q: since the changes to lists persist, does that mean we dont have to use returm statements with lists?

A1:  You can make changes to lists without using return, but sometimes you will want to use lists.


Q: is there any cs course about how the framework of the internet works?

A1:  live answered


Q: If I use breaks correctly is that considered good style?

A1:  Yes!


Q: In that last example I still don’t understand why the program would print the original list if num_list has been reassigned [1,2,3]

A1:  live answered


Q: what's the proper way to format a doctest? I wasn't able to make them successfully

A1:  Check out the examples from Chris’s lecture on Wednesday.


Q: So I guess the difference is that with lists, unlike integers let’s say, you do not have to return them in the helper function to change the value?

A1:  that is one difference.


Q: For the example at the end, why was append.(9) on list called new_list and not values?

A1:  live answered


Q: any tips if i’m feeling behind/ like the class is moving too fast for me?

A1:  Come to laIR and office hours with conceptual questions! You can also rewatch some of the lectures, go over the code from lectures, and do all of the section problems on the handout.


Q: can you extend a list but use the index to only add a few elements from the second list

A1:  Not only using extend, but you can write a program to do this!


Q: Is there something I have to do to used the 24hr delay option for assignment 2? Or do I just submit it the same way until tomorrow 1pm?

A1:  Nope just submit the same way tomorrow before 1pm.


Q: This may be covered later in the course, but is there a way to do calculations on lists in python? For example, if I made a list of populations of counties, could I make a histogram of the populations in python? Alternatively, could the list be exported to R to do calculations, and how could we learn how to do that?

A1:  We will learn this later in the course!


Q: so lists are sequences, so are indexing, and slicing work the same way for lists as they do for strings?

A1:  yes!


Q: What’s the difference between a for loop and a for each loop

A1:  live answered


Q: i dont understand the difference between the console and its uses vs pycharm and its uses?

A1:  live answered


Q: x = list.pop Here is x a variable whose value was the last element of list or is x a list with the 1 element which was the last element of list

A1:  x is a variable whose value was the last element of list.