2017-03-25 9 views
0

これをURIに送信しようとしましたが、10%間違っていました。入力576.43については、最後に2セントを与える。私は電卓ですべての計算を自分のコードと同じように行い、最後に3セントを得ました。なにが問題ですか?紙幣とコインは電卓で働いていますが、プログラムではありません

total = float(input()) 
bill100 = int((total)/100) 
total = ((total) - (bill100*100)) 
bill50 = int((total)/50) 
total = (total - (bill50*50)) 
bill20 = int(total/20) 
total = (total - (bill20*20)) 
bill10 = int(total/10) 
total = (total - (bill10*10)) 
bill5 = int(total/5) 
total = (total - (bill5*5)) 
bill2 = int(total/2) 
total = (total - (bill2*2)) 
coin1dolar = int(total) 
total = (total - coin1dolar) 
coin50 = int(total/0.50) 
total = (total - (coin50*0.50)) 
coin25 = int(total/0.25) 
total = (total - (coin25*0.25)) 
coin10 = int(total/0.10) 
total = (total - (coin10*0.10)) 
coin5 = int(total/0.05) 
total = (total - (coin5*0.05)) 
coin1cent = int(total/0.01) 
print("BILLS:") 
print(str(bill100) + " bills of R$ 100.00") 
print(str(bill50) + " bills of R$ 50.00") 
print(str(bill20) + " bills of R$ 20.00") 
print(str(bill10) + " bills of R$ 10.00") 
print(str(bill5) + " bills of R$ 5.00") 
print(str(bill2) + " bills of R$ 2.00") 
print("COINS:") 
print(str(coin1dolar) + " coins of R$ 1.00") 
print(str(coin50) + " coins of R$ 0.50") 
print(str(coin25) + " coins of R$ 0.25") 
print(str(coin10) + " coins of R$ 0.10") 
print(str(coin5) + " coins of R$ 0.05") 
print(str(coin1cent) + " coins of R$ 0.01") 

答えて

0

浮動小数点数が正確ではないという問題があります。あなたはそれについてin the python docsを読むことができます。浮動小数点値で除算を続けています。 coin1cent = int(round(total/.01))を実行して修正できます。

mod演算子(here)を参照する必要があります。

関連する問題