July 1st, 2021
Q: I had a little trouble testing pycharm, it didn’t seem to fin intro.py on my computer. Should I reinstall the app?
A1: Hmm. Can you post in Ed describing your troubles? We can take a closer look there
Q: I was having the error message when creating python intepretor
A1: What was the error message you were getting?
Q: Attribute error
A1: Can you post on Ed, or stop by LaIR / office hours?
Q: I posted on Ed and I was told to attend office hours. I tried connecting at 10:20 today but no one was there
A1: can you email me?
Q: do we need pycharm for today?
A1: Looking at the slides it seems like we’re doing experimental server examples. But I would recommend you start downloading it soon because you need Pycharm for your next homework assignment :) Drop by Office hours if you need help and instructions are on the website
Q: Can we put this class on our college apps and if so how would we prove we actually took the class (for example do we get a report card or transcript to send to colleges)?
A1: I put all classes that I took on my college apps! I believe you have access to a transcript on Axess (a Stanford website) but I’m not 100% sure. Tara (the head TA) would probably have a better answer (you can shoot her an email; she’s super responsive)
Q: How is the quiz going to be? It is similar to the hws?
A1: It will have a few problems and will be timed (usually about 20-30 minutes but more details will be announced soon). A practice exam and practice problems will be released on the class website. Understanding the homework, doing section problems, and quiz practice problems is good preparation :)
Q: Is it okay if I use the ultimate edition for Pycharm? I got it free for educational purposes using my school ID
A1: mmmm this is a great question that I do not know the answer to. We can ask Juliette at the end of lecture or you can post on Ed/email Tara to get an answer from her. I know the most important part of the Pycharm installation is follow the settings that we provide in the instructions on the website.
A2: Yep you can!
Q: Sarah, are you studying a mayor in CS at stanford? How was the admission process?
A1: I’m probably going to study CS at Stanford (I haven’t officially declared but probably will in the fall). I had a untraditional route to Stanford. I did not get in as a freshman. I transferred to Stanford after doing 2yrs of college at another institution. The admission process is like a lottery. So many qualified applicants apply.
Q: after s = s + something, we can’t edit the + something again, right?
A1: You could do that operation again to create a new string to add something again. But yes, Python strings are immutable (a term you’ll learn soon) meaning they cannot be modified after they are created.
Q: In looping over string, will the numbers repeat or the letters?
A1: mmm can you clarify your question?
Q: Will the answer me 12345 or nnnnn for pytho'n'
A1: If your string is s = python and you do a for loop like for i in range(len(s)) i will equal 0, 1, 2, 3, 4, 5. I answered a question but maybe not your so please follow up if you still have questions!
Q: What did Juliette major in?
A1: CS!
Q: does len(s) gives us the length of the string
A1: Yes!
Q: what's the purpose of result = '' again?
A1: That’s how you create an empty string. Great question!
Q: Even though this class is a more introductory level do you think great performance in it would reflect well when applying to a CS major?
A1: Yes! This is the introductory CS class at Stanford! You learn a lot about coding and it a challenging and rigorous class. As a cavaet, I know nothing about admissions and I can only speak about my experiences. My answers could be totally wrong in terms of admissions (My answers about admissions aren’t “endorsed” by Stanford). Happy to talk about my experiences though!
Q: does 2 * s[i] works?
A1: This would not work because s[i] is a character not a number. i is a number, s[i] is a character from a string
Q: How did we get xyz in the question when we didnt mention it anywhere?
A1: Great question! “xyz” is the value of s, so s = “xyz”. When the function double_char is called a value for the parameter s has to be inputtted and the user inputtted “xyz” in this case
Q: can you explain the empty quotes?
A1: Yes! The empty quotes is the empty string (a string with no characters). We created an empty string and then “built it up” in our for loop
Q: why does s[i] return chars
A1: s[i] indexes inside of the string s at the index i. Say you have the string s = “Hello”, at index i = 0, s[i] equals “H” and when i = 1, s[i] = “e” etc.
Q: Could we use result +=... instead of result = result +...?
A1: Yep!
Q: can you just use a for each loop to loop over all char?
A1: Yes! for ch in s: is a common pattern that will be discussed soon!
Q: does & or && work for and?
A1: Unfortunatetly no. You have to use and
Q: Why would you use and instead of or in this situation?
A1: Because the character cannot be a or b. If we used or instead of and then it wouldn’t work because a or b would pass the if statement
Q: in the not ab problem what would happen if you did or and not and?
A1: If you did if s[i[ != ‘a’ or s[i[ != ‘b’:, then a character would get added to the string as long as it wasn’t not both a or b (which is impossible because a character can only be 1 thing). For this type of problem you don’t want the character to be added if it is ‘a’ or ‘b’. It’s a weird translating from English to coding thing.
Q: does it work if you write if s[i] != 'a' and 'b'?
A1: No it doesn’t. The expressions on the opposite side of the and are read independently so you could get an error because ‘b’ is not a boolean.
Q: I am currently installing the Python interpreter and was asked if I wanted to "add launchers dir to the PATH." Should I do this?
A1: Yes! Check this box :) https://web.stanford.edu/class/cs106a-8/handouts/installingpycharm.html#
Q: in not ab what did result += s[i] do?
A1: Great question! result += s[i] adds the character s[i] to the string result. So if result = “Hell” and s[i] = “o” after this line runs we would have result = “Hello”
Q: how do you do xor in python
A1: mmm honestly I’m not sure if Python has an xor (I can Google and check). XOR isn’t covered in this class.
A2: XOR is typically a bitwise operator and we don’t work with bits in this class (CS 107 covers bitwise operations)
Q: What’s the difference between for i in x or for i in range(len(x))?
A1: This is the difference between the two for loops. We have for range loops and for each loops. The syntax for for each loops is: for i in x or more commonly for strings for ch in s. The syntax for for range loops is: for i in range(len(x)) or more commonly for i in range(len(s)) where i will be an index in the string.
Q: for the functions that the current function uses, do they have to be above the original function like in C++, or they can just be anywhere you want?
A1: Great question! In Python, your helper functions can be in any order. You don’t have to worry about forward declaration like in C++.
Q: Are grids like arrays?
A1: Similar to 2D arrays
A2: Similar yes :)
Q: does grid works like arrays in other languages?
A1: Similar to 2D arrays yes
Q: I didnt understand in bounds for Grid. Can you please explain?
A1: Of course! Grids have bounds (say it’s a 5x5 grid). Anything outside of those values (say (12, 14)) would be out of bounds. grid.inbounds(x, y) checks if a coordinate is inside of the grid bounds and returns true if it is and false if it is not.
Q: if you don’t set a value to the grid location is it automatically?
A1: I believe it will have a default value of None or 0. I’ll confirm with Juliette at the end
Q: What is a peep?
A1: A marshmallow candy that’s shaped like a bird and bright yellow https://www.google.com/search?q=peep+candy&oq=peep+candy&aqs=chrome..69i57j35i39l2j46i199i291i433l2j69i61l3.2866j0j9&sourceid=chrome&ie=UTF-8
Q: is there like a vector or arraylist in python?
A1: Yes! It’s called a list. We’ll learn about it soon :)
Q: follow up question, is list like a balanced tree that support logn time complexity for erasing elements?
A1: Great question! I did a Google search and it looks like the time complexity to delete an element from a list is O(n) (For others reading, we will not cover time complexity or Big O in this class; You learn about this in CS106B)
Q: Is “grid” a built in python functionality? If so, is there a place with more documentation on it?
A1: https://web.stanford.edu/class/cs106a/references/grid/grid-reference.html Here’s a reference that will be posted on our class website soon.