温度转换
#TempConvert.py """eval()评估函数:去掉参数最外侧引号并执行余下语句的函数""" """TEXT""" """{}表示槽,后续变量可以填充到槽中""" """.2f表示填充变量F取小数点后2位""" TempStr = input("请输入带有符号的温度值:") if TempStr[-1] in ['F','f']: C = (eval(TempStr[0:-1]) - 32)/1.8 print("转换后的温度是{:.2f}C".format(C)) elif TempStr[-1] in ['C','c']: F = 1.8*eval(TempStr[0:-1]) + 32 print("转换后的温度是{:.2f}F".format(F)) else: print("输入格式错误") #样例二 符号C和F在前 ''' T = input("") if T[0] in ['F']: C = (eval(T[1:])-32)/1.8 print("C{:.2f}".format(C)) elif T[0] in ['C']: F = 1.8*eval(T[1:])+32 print("F{:.2f}".format(F)) else: print("") '''
数字转换
'''输入123,输出一二三''' #样例一 '''end="" 给输出结果加个空格而不是回车 ''' Text = ['零','一','二','三','四','五','六','七','八','九'] PosInt = input("") for c in PosInt: print(Text[eval(c)],end="")' #样例二 ''' template = "零一二三四五六七八九" s = input() for c in s: #print(template[eval(c)],end="") '''
汇率转换
Num = input("") if Num[0:3] in ["RMB"]: USD = eval(Num[3:])/6.78 print("USD{:.2f}".format(USD)) elif Num[0:3] in ["USD"]: RMB = eval(Num[3:])*6.78 print("RMB{:.2f}".format(RMB))