Python Lab Questions
- Write a program to count change:
- prompt the user for the number of quarters, dimes, nickels,
and pennies
- compute the total value
- print the answer
- ask the user if (s)he wants to continue, and loop if yes.
- (more advanced) Write a program to make change
- prompt the user for the total amount of money
- 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.
- print the answer
- ask the user if (s)he wants to continue, and loop if yes.
- test your program with .75, it should print '3 quarters'
- You will need to determine which formats of input your program will
accept, e.g. $0.75, .75, 75 cents
- (not for the faint of heart) The previous problem does not always
give the minimum
number of coins. Dynamic programming will give the minimum.
- 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
- 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.
- The minimum has at least one quarter in the answer
- The minimum has at least one dime in the answer
- The minimum has at least one nickel in the answer
- The minimum has at least one penny in the answer
- Use a dictionary to remember which values you have already computed,
so you don't compute them again.
Graphics
- use graphics.py which can be downloaded from the drupal site
- Draw a circle and set fill color to be yellow
- Draw a rectangle
- Draw a line
- Draw a smiley face