Home > Backend Development > Python Tutorial > How to convert temperature with python code?

How to convert temperature with python code?

coldplay.xixi
Release: 2020-06-20 15:24:23
Original
20020 people have browsed it

How to convert temperature with python code?

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
Copy after login

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
Copy after login

Or: Use IDE to open the above file and press F5 to run (recommended)

How to convert temperature with python code?

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template