Chapter 2 Algorithm Workbench

  1. Write Python code that prompts the user to enter his or her height and assigns the user’s input to a variable named height.

  2. Write Python code that prompts the user to enter his or her favorite color and assigns the user’s input to a variable named color.

  3. Write assignment statements that perform the following operations with the variables a, b, and c:

    1. adds 2 to a and assigns the result to b

    2. Multiplies b times 4 and assigns the result to a

    3. Divides a by 3.14 and assigns the result to b

    4. Subtracts 8 from b and assigns the result to a.

  4. Assume the variables result, t, w, x, y, and z are all integers, and that w = 5, x = 4, y = 8, and z = 2. What value will be stored in result after each of the following statements execute?

    1. result = x + y

    2. result = z * 2

    3. result = y / x

    4. result = y - z

    5. result - w // z

  5. Write a Python statement that assigns the sum of 10 and 14 to the variable total.

  6. Write a Python statement that subtracts the variable down_payment from the variable total and assigns the result to the variable due.

  7. Write a Python statement that multiplies the variable subtotal by 0.15 and assigns the result to the variable total.

  8. What would the following display?

    1. a = 5

    2. b = 2

    3. c = 3

    4. result = a + b * c

    5. print(result)

  9. What would the following display?

    1. num = 99

    2. num = 5

    3. print (num)

  10. Assume the variable sales references a float value. Write a statement that displays the value rounded to two decimal points.

  11. Assume the following statement has been executed:

    1. number = 1234567.456

    2. Write a Python statement that displays the value referenced by the number variable formatted as

    3. 1, 234, 567.5

  12. What will the following statement display?

    1. print (‘George’, ‘John’, ‘Paul’, ‘Ringo’, sep=’@’)

robot