1 tempStr = input("请输入带有符号的温度值:") 2 if tempStr[-1] in ['F','f']: 3 c = (eval(tempStr[0:-1])-32)/1.8 4 print("转换后的温度是{}c".format(c)) 5 elif tempStr[-1] in ['C','c']: 6 f = 1.8 * eval(tempStr[0:-1])+32 7 print("转换后的温度是{}f".format(f)) 8 else: 9 print("输入格式有误")
1 distance = input("请输入带有符号的值:") 2 if distance[-2:] in ['nm','NM','nM','Nm']: 3 KM = eval(distance[0:-2])*1.8 4 print("转换后的公里是{:.2f}KM".format(KM)) 5 elif distance[-2:] in ['km','KM','kM','Km']: 6 NM = eval(distance[0:-2])/1.8 7 print("转换后的海里是{:.2f}NM".format(NM)) 8 else: 9 print("输入格式有误")
1 money = input("请输入金额:") 2 if money[0:1] in ['¥']: 3 R = eval(money[1:])*0.1547 4 print("转换后的美元是${:.2f}".format(R)) 5 elif money[0:1] in ['$']: 6 D = eval(money[1:])*6.4655 7 print("转换后的人民币是¥{:.2f}".format(D)) 8 else: 9 print("输入格式有误")