Lecture Materials

Class Announcements

Assignment 2 will be released after class today. There are three parts to the assignment and all parts are due by Tuesday, July 6th at 11:55pm PT.

Questions & Answers


Q: when should we download pycharm/when do we need it?

A1:  You will need Pycharm for the homework released today so download it as soon as you can :)


Q: Why does my pycharm say 3.8 instead of 3.9?

A1:  That is fine. Sometimes Pycharm labels it as an earlier version even though it is 3.9


Q: Are the instructions to download Pycharm going to be on the homework assignment?

A1:  There is a handout on the class website. https://web.stanford.edu/class/cs106a-8/handouts/installingpycharm.html


Q: If we need to miss class for something such as travelling, who should we email to inform about the absence?

A1:  Also if you need to miss your section, please email your section leader to let them know :)

A2:  If you need to miss lecture, you an watch the recording on Canvas without emailing anyone. If you need to miss your section, please attend an alternate section that week. You can find other section times and zoom links on Ed.


Q: About when would the hw be graded? Are the grades posted on the same link as our turned in hw?

A1:  Your section leader will reach out with information on how to schedule a one-on-one interactive grading session throughout this next week. You will receive your grade during that session.


Q: Will we be quizzed on the info presented today by Katie, or just coding?

A1:  It will not be on the quizzes, but it can show up on assignments.


Q: Will we be using PyCharm today during class?

A1:  Looking at the slides it looks like we’re mostly working on the experimental server


Q: Do we need pycharm community or pycharm professional?

A1:  You should download Pycharm community. Please follow the instructions on the class website: https://web.stanford.edu/class/cs106a-8/handouts/installingpycharm.html


Q: What happened to tara? hahah

A1:  If you need to talk to her, you can drop by her office hours or send her an email :)

A2:  Tara is totally good! She’s still the head TA for this class. I just do the Q&A with her now :)


Q: I downloaded pycharm but i couldn’t find the version 3.9 of the interpreter, only the 3. Should I download that one? I’m using a mac

A1:  Your mac might have python 3.8 (that’s what my mac has). I believe you have to download Python 3.9 (first step in the instrustions on the class website). Feel free to drop by office hours if you still have downloading problems


Q: what about double

A1:  Floats are the Python equivalent

A2:  Python does not have a double variable type


Q: can python do casting?

A1:  Yes, if you want to convert a float to an integer for example you can wrap it in int()


Q: Is float the term in python for a number like 1.2?

A1:  Yes, a float is a decimal in Python


Q: Does // always round down?

A1:  Yes, integer divison always rounds down


Q: so if you do int division it always truncates the float?

A1:  Yes


Q: Is it possible to do a division operation like // that would just round to the closest int?

A1:  mmm really good question! I don’t know of one off the top of my head but let’s ask Juliette at the end of lecture.


Q: is “score” what the user inputs?

A1:  In a sense yes. Score is the name of the function parameter. When a user calls your function, they have to put in a value (like 5) for score.


Q: Why does the code not stop running after the first return? I thought she said it didn’t run any code after return.

A1:  The first return (return score * 12) only runs if the if statement above is true. If the score is >= 5, then score * 12 will be returned and the function will end. Otherwise the second return statement will run


Q: Could we use an if/else format as well?

A1:  Yes! But we don’t need the else because the return statement gaurantees that the function will end when needed.


Q: I know there is a “if.. else” statement in Java, is this. similar to that? is there a “if.. else” statement in Python?

A1:  Sort of! Python also has if/else that you will use. But when an if statement code body ends in a return statement, you don’t have to say else because you are gauranteed to be in the else statement if the if condition fails.


Q: Can we use if not?

A1:  Yes you can use not inside if statements (ex. if not bit.front_clear())


Q: Would it matter if she did < first and then >= second?

A1:  No, you could say if score < 5 return score * 10. Otherwise return score * 12


Q: For winnings1, would writing if score <=4 (plus the appropriate code) and if score >= 5 (plus the appropriate code) be both stylistically correct and is one way preferred over the other?

A1:  It’s best to only use one if statement because in a sense the two if statements are redundant. Peresonally, I would write either if score >= 5 or if score < 5 because those follow the problem description.


Q: we could also use and here right? if score>=4 and score<=9?

A1:  Yes, you can use and to unite two if statements.


Q: is there else if in python?

A1:  Yes! It’s elif


Q: can we use "|| " and "&&" in python while writting if statements

A1:  No, you have to use words (Python is all about readablity). So for or you would write or instead of || and and instead of &&


Q: generally speaking, can we use “or” in an if statement? for example if score < 5 or score > 10. I know in c++ we use || so is there something equivalent in python?

A1:  Yes you can use or in if statements. You use the word or instead of ||


Q: Around when will assignment 2 be availible?

A1:  Today after lecture :)


Q: how does the computer know what is_raining means?

A1:  is_raining = True # if it is raining is_raining = False # if it is not raining


Q: General question: what kind of projects can we work on knowing python? Like what can we do with python? Websites, etc?

A1:  So many things! Machine learning, data analysis, images and much more!


Q: can != and ‘not’ be used interchangably?

A1:  Yes but sometimes stylistically one works better than the other


Q: How far are we going to get with python in this course?

A1:  You won’t learn many of the libraries but you’ll have a super solid foundation!


Q: do we go into classes?

A1:  Perhaps, but probaby not


Q: Will we cover OOP

A1:  We’re not going to go in depth into classes in this course. CS106B covers classes


Q: Are we going to get into learning trees? For machine learning?

A1:  No, we’re not


Q: What is the best programming language for mobile app development? (both ios and android)

A1:  Swift for ios and React or native react for andriod


Q: Can you please go through how to use Pycharts again?

A1:  Come to LaIR of office hours to go more into detail for Pycharm


Q: How big is the Stanford campus and is it easy to get lost in there? Just wondering because I heard if it wasnt pandemic we would be taking classes on campus :D

A1:  It’s HUGE!


Q: When will we be learning data visualisation?

A1:  Week 5!


Q: is it true many stanford students own bikes due to campus being huge?

A1:  Yes everyone has bikes haha