I am making a change program in python. The user must enter the amount in dollars, and then the program will calculate the change in twenties, tens, five, four, a quarter, nickel and pennies. I was instructed to use the round function for pennies, because if I enter the amount of $ 58.79, the Program tells me to return 3 pennies when it should be 4. Is there a way to round these pennies?
I know the penny value is 0.01, but python reads this as .100000000001, which I believe is the problem.
Any help is appreciated, here is the section I need to round up:
change = input("Please enter the amount to change: $")
print "To make change for $",change,"give the customer back:"
twenties = int(change/ 20)
print twenties, "twenties"
change = change - twenties *20
tens = int(change / 10)
print tens, "tens"
change = change - tens *10
fives = int(change / 5)
print fives, "fives"
change = change - fives *5
ones = int(change / 1)
print ones, "ones"
change = change - ones * 1
quarters = int(change / .25)
print quarters, "quarters"
change = change - quarters * .25
dimes = int(change / .10)
print dimes, "dimes"
change = change - dimes * .10
nickels = int(change / .05)
print nickels, "nickels"
change = change - nickels * .05
pennies = int(change / .01)
print pennies, "pennies"
source
share