Home  >  Article  >  Backend Development  >  Write temperature conversion in python

Write temperature conversion in python

尚
Original
2019-10-22 15:42:389708browse

Write temperature conversion in python

Python writes Celsius temperature to convert to Fahrenheit:

celsius = float(input('输入摄氏温度: '))
 
# 计算华氏温度
fahrenheit = (celsius * 1.8) + 32
print('%0.1f 摄氏温度转为华氏温度为 %0.1f ' %(celsius,fahrenheit))

Use formula:

fahrenheit = (celsius * 1.8) + 32

Python writes Fahrenheit temperature to convert to Celsius:

fahrenheit = float(input('输入华氏温度: '))
 
# 计算摄氏温度
celsius = (fahrenheit - 32) / 1.8
print('%0.1f 华氏温度转为摄氏温度为 %0.1f ' %(fahrenheit,celsius))

Formula:

celsius = (fahrenheit - 32) / 1.8

The above is the detailed content of Write temperature conversion in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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