# greedy with Pyhton 3 - how to code the largest coins first with Python

what would be the easiest way to use python for calculating the coins with the different quarter, dime, noony, penny ? I've seen some declaration with an array of values ? And waht i've done isn t working because i can't figure out how to order with python to use largest coins ?? Any hints please ??

that the result I get :

``````~/workspace/pset6/ \$ python greedy.py
Oh Hai ! How much change is owed?
0.41
164.0
``````

here section of code :

``````else:
#convert the input integer in rouded money +
#convert the dollars in cents
amount_cents = (round((amount_dollars)*100))

#while True:
#loop until there is still change
if amount_cents > 0:

# number of coins
q = (amount_cents/0.25)
amount_remain_q = (amount_cents-(q*0.25))
d = (amount_remain_q/0.10)
amount_remain_d = (amount_remain_q-(d*0.10))
n = (amount_remain_d/0.05)
amount_remain_n = (amount_remain_d-(n*0.05))
p = (amount_remain_n/0.01)

#number of total coins
coins = q+d+n+p
print(coins)
``````

## 1 Answer

You've converted the user entry into an integer representing the number of cents. But then, in your loops, you are using 0.25 (which, in this context means a quarter of a cent). Should that be 25 and 10 and 5 and 1? (not decimals?)

• tks i notice it when i got up this morning – Genevie Sep 3 '17 at 16:11
• in python, is worth it to convert the amount in cents and in round ? – Genevie Sep 3 '17 at 16:14
• i mean is there a simplest way to do so ? simpler than in C which was only 4 lines total ? – Genevie Sep 3 '17 at 16:15
• actually, its works for the integer but not with 0.41 : ~/workspace/pset6/ \$ python greedy.py Oh Hai ! How much change is owed? 0.41 1.64 – Genevie Sep 3 '17 at 17:14
• oh i got it! it s about the // vs /. i found it in other post. cs50.stackexchange.com/questions/25591/… – Genevie Sep 3 '17 at 17:26