多国汇率换算

 
#练习二 多国汇率换算,以人民币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()

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值