2017-02-09 152 views
-4

我有一個問題,程序不會顯示用戶想要轉換的數量。另外你如何將數字四捨五入到小數點後三位,有什麼想法?貨幣轉換器

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包括round()功能,lets you specify你想要位數。因此,您可以使用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

你知道我可以在我的代碼中完全實現嗎? –