Homework Solution

Expressions

Problems to be Submitted (20 points)

  1. (5 points)

    Parts (a), (b), (e), (m), (q) of Exercise 1.1 on pages 15

    (a)An int with value 31
    (b)An int with value -5
    (e)A float with value 3.4
    (m)A str with value '121212'
    (q)A bool with value True

  2. (5 points)

    Part (d) of Exercise  1.2 on page 15

         +
       /   \
      *	1
     / \
    4  **
      /  \	
     3    2	
    

  3. (5 points)

    Part (a) of Exercise  1.4 on page 15

    703 * (w / h**2)
    as written algebraically, though due to associativety, the result would be the same if it were computed as
    703 * w / h**2

  4. (5 points)

    Exercise 1.9 on page 16

    For illumination, we'll show the state after each of the four commands.

    After x = 5:

             +-----+
    +--------|  x  |
    |   int  +-----+
    +----------+
    |    5     |
    +----------+
    

    After y = x + 3:

             +-----+              +-----+
    +--------|  x  |     +--------|  y  |
    |   int  +-----+     |   int  +-----+
    +----------+         +----------+
    |    5     |         |    8     |
    +----------+         +----------+
    

    After x = 2 * y:

             +-----+              +-----+
    +--------|  x  |     +--------|  y  |
    |   int  +-----+     |   int  +-----+
    +----------+         +----------+
    |   16     |         |    8     |
    +----------+         +----------+
    

    After y = x + 3:

             +-----+              +-----+
    +--------|  x  |     +--------|  y  |
    |   int  +-----+     |   int  +-----+
    +----------+         +----------+
    |   16     |         |   19     |
    +----------+         +----------+
    


Last modified: Friday, 07 September 2018