from decimal import Decimal
def currency_exchange():
currency = input()
exchange_rate = float(input())
if exchange_rate <= 0:
return 'Data error!'
if currency[-1] == '$':
currency_convert = Decimal(float(currency[-len(currency):-1:1]) * exchange_rate).quantize(Decimal('0.01'),
rounding='ROUND_HALF_UP')
return f'{currency_convert}¥'
elif currency[-1] == '¥':
currency_convert = Decimal(float(currency[-len(currency):-1:1]) / exchange_rate).quantize(Decimal('0.01'),
rounding='ROUND_HALF_UP')
return f'{currency_convert}$'
else:
return 'Data error!'
print(currency_exchange())
货币转换_
最新推荐文章于 2025-12-04 22:56:41 发布
本文介绍了一个简单的货币转换程序,该程序可以将美元($)和人民币(¥)互相转换。用户输入待转换的货币及其金额,程序会读取汇率并完成转换。
6432

被折叠的 条评论
为什么被折叠?



