81.5k views
25 votes
Write a program that asks the user for a (integer) number of cents, from 0 to 99, and outputs how many of each type of coin would represent that amount with the fewest total number of coins. When you run your program, it should match the following format:

User RLH
by
4.2k points

1 Answer

6 votes

cents = int(input("How many cents do you have? "))

ct = cents

quarters = cents // 25

cents -= (quarters*25)

dimes = cents // 10

cents -= (dimes * 10)

nickels = cents // 5

cents -= (nickels * 5)

pennies = cents // 1

print("With "+str(ct)+" cents you can have "+str(quarters)+" quarters, "+str(dimes)+ " dimes, "+str(nickels)+" nickels, "+str(pennies)+" pennies.")

I wrote my code in python 3.8. I hope this helps

User Jose Vf
by
4.5k points