Skip to content
Advertisement

Coin Change Maker Python Program

I am in a beginner programming course. We must do an exercise where we make a change maker program. The input has to be between 0-99 and must be represented in quarters, dimes, nickles, and pennies when the input is divided down between the four. I wrote a code that involved loops and whiles, but he wants something more easy and a smaller code. He gave me this as a way of helping me along:

c=int(input('Please enter an amount between 0-99:'))
print(c//25)
print(c%25)

He told us that this was basically all we needed and just needed to add in the dimes, nickles, and pennies. I try it multiple ways with the dimes, nickles, and pennies, but I cannot get the output right. Whenever I enter ’99’, I get 3 for quarters, 2 for dimes, 1 for nickles, and 0 for pennies. If anyone would be able to help me, that would be wonderful!

Advertisement

Answer

I’m now sure about what you want to achieve. Using the modulo operator you could easily find out how many quarters, dimes, nickles and pennies.

Let’s just say you input 99.

c=int(input('Please enter an amount between 0-99:'))
print(c//25, "quarters")
c = c%25
print(c//10, "dimes")
c = c%10
print(c//5, "nickles")
c = c%5
print(c//1, "pennies")

this would print out:

3 quarters
2 dimes
0 nickles
4 pennies
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement