Home >Backend Development >Python Tutorial >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!