How to convert temperature with python code?
Method for temperature conversion using python code:
Step 1: Analyze the calculation part of the problem
Step 2: Determine the function and use the IPO method for further analysis
Input: Fahrenheit or Celsius temperature value, temperature identifier
Processing: Temperature conversion algorithm
Output :Celsius or Fahrenheit temperature value, temperature identification
F:Fahrenheit temperature C:Celsius
Step 3: Design algorithm
C=(F-32)/1.8; F=C*1.8+32
Step Four: Write a program
#TempConvert.py val = input("请输入带温度表示符号的温度值(例如: 32C): ") if val[-1] in ['C','c']: f = 1.8 * float(val[0:-1]) + 32 print("转换后的温度为: %.2fF"%f) elif val[-1] in ['F','f']: c = (float(val[0:-1]) - 32) / 1.8 print("转换后的温度为: %.2fC"%c) else: print("输入有误")步骤五:调试、运行程序 在系统命令行上通过如下命令执行程序: C:\>python TempConvert.py
Or: Use IDE to open the above file and press F5 to run (recommended)
Recommended tutorial: " python video tutorial》
The above is the detailed content of How to convert temperature with python code?. For more information, please follow other related articles on the PHP Chinese website!