1
h02
CSE SPIS 2016
Name:
(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

ready? assigned due points
true Mon 08/01 09:00AM Tue 08/02 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 indicate.


Please read Chapter 2 in the Guttag textbook.

Note that on Page 10, there is one potential source of confusion:

For example:

After reading Chapter 2, answer these questions:

  1. (20 pts) Guttag discusses variables and names at some length on pages 11 and 12 (section 2.1.2) What are the four most important points that you would take away from this section?

  2. (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?

  3. (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?

  4. (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.

  5. (10 pts) Try the “finger exercise” on p. 20.