#练习二 多国汇率换算,以人民币cny、欧元eur、美元usd为例2020/10/7
def convert_currency(im,er):
out=im*er
return out
def main():
# global exchange_rate
usd_vs_cny = 6.79
usd_vs_eur =0.85
eur_vs_cny=8
currency_str_value = input('请输入带单位的货币金额:(退出程序请输入Q):')
currency_get=input('请输入想要得到的币种汇率单位')
i=0
while currency_str_value != 'Q':
i = i + 1
unit=currency_str_value[-3:]
if unit in 'cny':
if currency_get=='usd':
exchange_rate:1/usd_vs_cny
elif currency_get=='eur':
exchange_rate=1/eur_vs_cny
elif unit in 'usd':
if currency_get=='cny':
exchange_rate:usd_vs_cny
elif currency_get=='eur':
exchange_rate:usd_vs_eur
elif unit in 'eur':
if currency_get=='cny':
exchange_rate:eur_vs_cny
elif currency_get=='usd':
exchange_rate:1/usd_vs_eur
else:
exchange_rate=-1
if exchange_rate!=-1:
in_money=eval(currency_str_value[:-3])
out_money=convert_currency(in_money,exchange_rate)
print('转换后的金额:',out_money)
else:
print('不支持这种货币功能')
currency_str_value = input('请输入带单位的货币金额(退出程序请输入Q):')
print('程序已退出')
if __name__=='__main__':
main()