Python 程序:将摄氏温度转换为华氏温度
在此程序中,您将学习将摄氏温度转换为华氏度并进行显示。
要理解此示例,您应该了解以下 [Python 编程]( "Python tutorial")主题:
在下面的程序中,我们以摄氏度为单位将温度转换为华氏度。 它们由以下公式关联:
celsius * 1.8 = fahrenheit - 32
源代码
# Python Program to convert temperature in celsius to fahrenheit # change this value for a different result celsius = 37.5 # calculate fahrenheit fahrenheit = (celsius * 1.8) + 32 print('%0.1f degree Celsius is equal to %0.1f degree Fahrenheit' %(celsius,fahrenheit))
输出:
37.5 degree Celsius is equal to 99.5 degree Fahrenheit
我们建议您创建一个 Python 程序,使用以下公式自行将华氏温度转换为摄氏温度
celsius = (fahrenheit - 32) / 1.8