目录
判断题
Python变量使用前必须先声明,并且一旦声明就不能在当前作用域内改变其类型了。
错误
温度转化程序
问题描述】在温度刻画的不同体系中,摄氏度以1标准大气压下水的结冰点为0度,沸点为100度。华氏度以1标准大气压下水的结冰点为32度,沸点为212度。如何利用程序辅助进行摄氏度和华氏度之间的转换
设计算法:根据华氏和摄氏温度定义,其单位刻度对应温度关系为(212-32)/(100-0)=1.8,转换公式如下:
C = ( F – 32 ) / 1.8
F = C * 1.8 + 32
【输入形式】输入温度加温度制式的代表字母
【输出形式】转换后的温度加温度制式的代表字母
【样例输入输出1】
What is the temperature?82F
The converted temperature is 28C
【样例输入输出2】
What is the temperature?28C
The converted temperature is 82F
a = input("What is the temperature?")
if a[-1] in "Ff":
print("The converted temperature is "+str(round((eval(a[:-1])-32)/1.8,0))[:-2]+"C")
else:
print("The converted temperature is "+str(round((eval(a[:-1])*1.8)+32,0))[:-2]+"F")