|CSE SPIS 2017|
|(full first and last name)|
|UCSD email address:||@ucsd.edu|
| Optional: name you wish to be called|
if different from name above.
| Optional: name of "homework buddy"
(leaving this blank signifies "I worked alone"
h02: Guttag, Chapter 2
|true||Wed 08/09 10:15AM||Fri 08/11 09:00AM|
You may collaborate on this homework with AT MOST one person, an optional "homework buddy".
Bring this with you to your first lecture on the due date indicated.
Please read Chapter 2 in the Guttag textbook.
After reading Chapter 2, answer these questions:
(20 pts) Guttag discusses variables and names at some length on pages 12 and 13 (section 2.1.2) What are the four most important points that you would take away from this section?
(20 pts) In Python, indentation and nesting are signficant concepts. Guttag offers an explanation of these, with some examples. If you feel like you understand these from his explanation, my question is: how would YOU explain these concepts to someone new to the Python language? That is: use your own words, not Guttag’s. If you feel like your understanding is still not firm, what questions would you ask about indentation and nesting, after reading Guttag’s explanation?
(20 pts) Suppose you want a Python program to ask the user a question (e.g. “What is your name”?) and store the answer in a variable called “users_name”. How do you do that?
(30 pts) Guttag discusses iteration in Section 2.4. A while loop continues while its condition is true, and ends when its condition is false. If it’s condition is false the first time it is encountered, the body of the loop is never even executed once.
These leaves us with three possibilities:
- A while loop that is never executed
- A while loop that will be executed a finite number of times (e.g. 3)
- A while loop that will never terminate (a so-called “infinite loop”)
Write an example of each of these kinds of while loops in Python. Try them in IDLE and see what happens.
(10 pts) Try the first “finger exercise” on p. 24.
Note on how to turn in your homework assignment
As mentioned in homework 1, all your homework assignments for FOCS share a single github repo. So we will the same repo you recreated there (it should have been named homework_firstname_firstLetterLastname). In that repo, for every homework assignment, create a file named hwkxx.md where xx is the number of that homework assignment. So this homework’s file should be named hwk02.md. Write your answers in that file and push it to your homework repo.