Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Coin Change Maker Python Program

Tags:

python

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!

like image 440
bulsona15 Avatar asked Aug 03 '26 01:08

bulsona15


2 Answers

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
like image 175
Saimu Avatar answered Aug 04 '26 14:08

Saimu


n = int(input("Enter a number between 0-99"))
q = n // 25
n %= 25
d = n // 10
n %= 10
ni =  n // 5
n %= 5
c = n % 5
print(str(q) +" " + str(d) +" " + str(ni) + " " + str(c))

I hope this helps? Something like this but don't just copy it. Everytime you divide by 25 10 5 you must lose that part because it's already counted.At the end print what ever you want :).

like image 40
Hybr1d Avatar answered Aug 04 '26 13:08

Hybr1d