# Another program to make change # Matt Bishop, July 11, 2012 # for COSMOS 2012, Cluster 4 # # print the amount in a gramatically correct way # def prnumber(amt, sing, plur): # if there's 1 -- singular if amt == 1: print(amt, sing, end=' ') # otherwise it's plural else: print(amt, plur, end=' ') # set flag for looping go_on = "yes" # # loop making change until told to quit # while go_on == "yes": # get the amount to make change for temp = input("How many cents do you want me to make change for? ") change = pchange = int(temp) # take out the qurters nquarters = change // 25 change %= 25 # take out the dimes ndimes = change // 10 change %= 10 # take out the nickels nnickels = change // 5 # what's left are the pennies npennies = change % 5 # give the change prnumber(pchange, "cent", "cents") print("is", end=' ') prnumber(nquarters, "quarter", "quarters,") prnumber(ndimes, "dime,", "dimes,") prnumber(nnickels, "nickel, and", "nickels, and ") prnumber(npennies, "penny", "pennies") print("") # do another one? try: go_on = input("Again ('yes' for yes, anything else to stop): ") except EOFError: go_on = "no"