IPO Input:温度 Process:处理 Output:输出
C=(F-32)/1.8 F=C*1.8+32 这是核心
判断是C还是F,注意大小写 if str[-1] in ['F','f'] or if str[-1] in ['C','c']
这是我自己编写的:
TempStr=input('input the degree with F or C:')
if TempStr[-1] in ['F','f']:
C=(eval(TempStr[0:-1])-32)/1.8
print('after converting,the temperature is %d C',C)
if TempStr[-1] in ['C','c']:
F=eval(TempStr[0:-1])*1.8+32
print('after converting,the temperature is %d F',F)
这是运行的结果:
input the degree with F or C: 32F
Traceback (most recent call last):
after converting,the temperature is %d C 0.0
File "F:/flupytr/degree change.py", line 7, in <module>
print('after converting,the temperature is %d F',F)
NameError: name 'F' is not defined