2017-02-09 2 views
-4

私はプログラムがユーザーが変換したいと思った量を表示しないという問題があります。また、どのように小数点第3位、任意のアイデアに丸めますか?通貨変換器

money = int(input("Enter the amount of money IN GDP you wish to convert :")) 

USD = 1.25 
EUR = 1.17 
RUP = 83.87 
PES = 25.68 

currency = input("Which currency would you like to convert the money into?") 

if currency == "USD": 
    print(money) * USD 
elif currency == "EUR": 
    print(money) * EUR 
elif currency == "RUP": 
    print(money) * RUP 
elif currency == "PES": 
    print(money) * PES 
+0

これは、丸めのために役立つはずhttp://stackoverflow.com/questions/455612/limiting-floats-to-two-decimal-points – spijs

+4

行い**ません* *コードのポストピクチャ、ポストコードとしての*書式付きテキスト*、質問自体。 –

+0

"私はプログラムがユーザーが変換したいと思った量の量を表示しないという問題があります" - 何が問題なのですか? –

答えて

0

Pythonは、あなたがしたい桁数をlets you specifyround()機能を含んでいます。したがって、round(x, 3)を使用して、小数点以下3桁までの通常の丸めを行うことができます。

print(round(5.368757575, 3)) # prints 5.369 

更新

あなたはこの方法であなたのコードを更新することができます。

money = int(input("Enter the amount of money IN GDP you wish to convert: ")) 

USD = 1.25 
EUR = 1.17 
RUP = 83.87 
PES = 25.68 

currency = input("Which currency you like to convert the money into?: ") 

if currency == "USD": 
    print(round(money * USD, 3)) 
elif currency == "EUR": 
    print(round(money * EUR, 3)) 
elif currency == "RUP": 
    print(round(money * RUP, 3)) 
elif currency == "PES": 
    print(round(money * PES, 3)) 

これは、出力:

Enter the amount of money IN GDP you wish to convert: 100 
Which currency you like to convert the money into?: USD 
125.0 

Enter the amount of money IN GDP you wish to convert: 70 
Which currency you like to convert the money into?: RUP 
5870.9 
+0

私はこれを私のコードのどこに正確に実装できますか? –