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
8 ответов
+ 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
+ 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.
+ 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)
+ 2
what's wrong?
+ 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]
+ 1
thank you #Seamiki :)
0
thx but didn't get that :)
0
thx does not work properly. :)