问题描述
TypeError: eval() arg 1 must be a string, bytes or code object
eval()
函数的参数必须是字符串、字节或代码对象
问题记录
错误案例
tmpstr = input('请温度值(F表示华氏度,C表示摄氏度):')
if tmpstr[-1].upper() == 'F':
c = (eval(tmpstr[0:-1] - 32)) / 1.8
print('转化后的温度是{:.2f} C'.format(c))
改进方案
c = (eval(tmpstr[0:-1]) - 32) / 1.8