0

Python problem in while, for, and ..

hello, I am trying to write a program which takes an amount of money in Euro zone and calculates the minimum number of coins. I wrote like 10 of them and each has its own problem, please help. Thank you LINK: https://code.sololearn.com/cB3c2f2c57u8/#py

2nd Nov 2017, 3:37 PM
Dariush Shiri
Dariush Shiri - avatar
8 Respostas
+ 3
imprecision is due to how python handles the float 0.6 is actually 0.5999999999 se this updated code that should do the trick rounding the float to the second decimal, i'll edit my previous post https://code.sololearn.com/cPdTOl9433eo/?ref=app
2nd Nov 2017, 5:18 PM
seamiki
seamiki - avatar
+ 3
example amount 13.6 divide the amount by the current coin if is bigger than zero store the value calculate the modulus to get the reminder assing the value of the reminder to the amount repeat the operation until with the updated amount and the next coin.
2nd Nov 2017, 4:34 PM
seamiki
seamiki - avatar
+ 3
ml = [2.0, 1.0, 0.5, 0.2, 0.1, 0.05, 0.02, 0.01] amount = float(input("Please Enter An Amount: ")) def money(amount): for i in ml: if amount//i>0: if i<=amount: print(amount,"in coins by",i, "=") print(amount//i) amount = round(amount%i,2) if amount == 0: break money(amount)
2nd Nov 2017, 4:49 PM
seamiki
seamiki - avatar
+ 2
what's wrong?
2nd Nov 2017, 4:58 PM
seamiki
seamiki - avatar
+ 1
it's supposed to give an answer like this: Input 13 Euro answer: you need 6 of 2 Euros and 1 means: [2 EUR, 2EUR, 2EUR, 2EUR, 2EUR, 2EUR, 1EUR]
2nd Nov 2017, 5:01 PM
Dariush Shiri
Dariush Shiri - avatar
+ 1
thank you #Seamiki :)
2nd Nov 2017, 5:23 PM
Dariush Shiri
Dariush Shiri - avatar
0
thx but didn't get that :)
2nd Nov 2017, 4:36 PM
Dariush Shiri
Dariush Shiri - avatar
0
thx does not work properly. :)
2nd Nov 2017, 4:57 PM
Dariush Shiri
Dariush Shiri - avatar