Python Lab Questions

  1. Write a program to count change:
    1. prompt the user for the number of quarters, dimes, nickels, and pennies
    2. compute the total value
    3. print the answer
    4. ask the user if (s)he wants to continue, and loop if yes.
  2. (more advanced) Write a program to make change
    1. prompt the user for the total amount of money
    2. use a greedy algorithm to compute the number of quarters, dimes, nickels, and pennies that will produce the correct total. The greedy algorithm uses as many of the largest-value coin first, then uses the next smaller coin on the remainder.
    3. print the answer
    4. ask the user if (s)he wants to continue, and loop if yes.
    5. test your program with .75, it should print '3 quarters'
    6. You will need to determine which formats of input your program will accept, e.g. $0.75, .75, 75 cents
  3. (not for the faint of heart) The previous problem does not always give the minimum number of coins. Dynamic programming will give the minimum.
    1. If you don't have any nickels (just pennies, dimes and quarters), then you should be able to find an example where the greedy algorithm does not give the minimum
    2. Write a [recursive version] of the function by returning the minimum of the following cases. You can try to write a non-recursive version. My guess is that you will find it even more difficult than the recursive version.
      1. The minimum has at least one quarter in the answer
      2. The minimum has at least one dime in the answer
      3. The minimum has at least one nickel in the answer
      4. The minimum has at least one penny in the answer
    3. Use a dictionary to remember which values you have already computed, so you don't compute them again.

    Graphics

  4. use graphics.py which can be downloaded from the drupal site
  5. Draw a circle and set fill color to be yellow
  6. Draw a rectangle
  7. Draw a line
  8. Draw a smiley face