我有一个问题,该程序无法显示用户想要转换的所需金额。另外,您如何将数字四舍五入到小数点后三位?
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
Python包含允许您指定所需位数的round()
功能。因此,您可以使用进行四舍五入至小数点后三位的普通舍入。round(x, 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
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句