汇率兑换学习笔记-V3.0


汇率兑换学习笔记-V3.0在汇率兑换学习笔记-V2.0基础上增加了循环语句while和用户可以一直查询,暂时只能查询一种货币:美元(USD)可以让用户选择性退出。

"""
Author:Li Lin
Function:exchange rate
Version:3.0
date:2019/10/16
2.0: Enter the judgment is based on RMB or US dollars, corresponding conversion
3.0:New feature: You can always run the program until the user chooses to exit
"""

# unit conversion
usd_vs_rmb = 6.77

# Currency input with units
currency_str_value = input('Currency input with units RMB(Press Q to exit): ')

i = 0

while currency_str_value != 'Q':
    i = i + 1
    # print('Number of cycles', i)
    # unit RMB
    unit = currency_str_value[-3:]

    if unit == 'CNY':
        # input RMB
        rmb_str_value = currency_str_value[:-3]
        # String conversion to numbers
        rmb_value = eval(rmb_str_value)
        # Exchange rate
        usd_value = rmb_value / usd_vs_rmb
        # output result
        print('USD output:', usd_value)

    elif unit == 'USD':
        # input USD
        usd_str_value = currency_str_value[:-3]
        # String conversion to numbers
        usd_value = eval(usd_str_value)
        # Exchange rate
        rmb_value = usd_value * usd_vs_rmb

        # output result
        print('CNY output: ', rmb_value)

    else:
        # Other cases
        print('The current version does not yet support this currency!')

    print('**************************************************************')
    # Currency input with units
    currency_str_value = input('Currency input with units RMB(Press Q to exit): ')

print('Program has exited!')
当前内容只有登录了才能查看,如果您已经注册,请登录
本文由 学习链 作者:学习链 发表,其版权均为 学习链 所有,文章内容系作者个人观点,不代表 学习链 对观点赞同或支持,未经许可,禁止转载,题图来自Unsplash,基于CC0协议。

发表评论