问题描述
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))
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/dc5da72738efe0f4c54827e56867d6a8.png)
改进方案
c = (eval(tmpstr[0:-1]) - 32) / 1.8
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/a22a6e537dfec81db22386e9371d02a2.png)