代码如下:
def curExchange(mWorth):
if mWorth[-1] in ['$']:
CNY = (eval(mWorth[0:-1]))*6.8833
print("可兑换的人民币为%.3f"%CNY)
elif mWorth[-1] in ['¥']:
USD = (eval(mWorth[0:-1]))*0.1452
print("可兑换的美元为%.3f"%USD)
else:
print("输入有误")
mWorth = input("请输入人民币或美元(使用¥和$标识):")
curExchange(mWorth)
运行结果: