# Correct Change

I am supposed to Design and write a Python program that gives exact change for an item purchased with \$5 or less. Use a float data type to represent money (You may want to multiply this number by 100 so that you get an integer for your calculation, such that \$5.00 represents 500 cents, \$2.35 represents 235 cents, etc.)

Below is my code:

amount = float(input('Enter item cost: '))
tender = float(input('Enter amount tendered: '))

change = int((tender - amount)*100)
dollars = change // 100
change = change % 100
quarters = change // 25
change = change % 25
dimes = change // 10
change = change % 10
nickels = change // 5
change = change % 5
pennies = change
#output
print(‘Dollar bills:’, dollars)
print(‘Quarters:’, quarters)
print(‘Dimes:’, dimes)
print(‘Nickels:’, nickels)
print(‘Pennies:’, pennies)

An expected output for an item that costs \$2.71 when the amount tendered is \$5.00, would be:

Dollars: 2 Quarters: 0 Dimes: 2 Nickels:1 Pennies:4

but my output is giving me:

Enter item cost: 2.71 Enter amount tendered: 5.00

Dollars: 2 Quarters: 1 Dimes: 0 Nickels: 0 Pennies: 4

What am I doing wrong? Any help would be appreciated…

1 Like

If the item costs `\$2.71` and you tendered `\$5.00`, the change is `\$2.29`
While you are here, you might want to check: How Do I Format My Code? for future posts! That will make your code more readable 