Exercises

September 6 - September 11, 2006

  1. 1. Copy and paste or save hiho.py into a new file.
    2. Modify the program so that it prints “FIFO” .
  2. Write a program with the following three functions:
    1. printFirstName - a function that prints your first name
    2. printLastName - a function that prints your last name
    3. printFullName - a function that prints your full name
    Make sure to test each function by calling it. Verify that it produces the correct result/side-effect.
  3. Write a program with the following functions:
    1. add - this function takes as input two numbers, adds them, and displays the result
    2. subtract - this function takes as input two numbers, subtracts the second from the first, and displays the result
    3. multiply - this function takes as input two numbers, multiplies them, and displays the result
    4. quotient - this function takes as input two numbers, divides the first by the second, and displays the result
    Make sure to test each function by calling it. Verify that it produces the correct result/side-effect.
  4. Modify your add/subtract/multiply/quotient program as follows:
    1. Modify your functions such that they return the result calculated
    2. Create two new functions, the first function should prompt the user for a number. You will have to call this function twice, once to get the first number and once to get the second number. The second function will take as input the results calculated by the functions add/subtract/multiply/quotient and will display all four results for the user.

Sami Rollins