Python 程序将摄氏度转换为华氏度

17 Mar 2025 | 阅读 2 分钟

在本教程中,我们将学习如何编写 Python 程序,将摄氏温度转换为华氏温度。

摄氏度

摄氏度是一种温度测量单位,也称为百分度,它是世界上大多数国家使用的 SI 派生单位。

它以瑞典天文学家安德斯·摄尔修斯的名字命名。

华氏度

华氏度也是一种温度标度,它以波兰出生的德国物理学家丹尼尔·加布里埃尔·华伦海特的名字命名,它使用华氏度作为温度单位。

假设我们有一个摄氏温度,我们的任务是将温度值转换为华氏度并显示出来。

示例

方法

我们可以输入摄氏温度,并应用从摄氏度到华氏度的转换公式,并在屏幕上显示。以下是摄氏度和华氏度的关系

T(华氏度)=(T(摄氏度)*1.8)+32

或者我们可以写成

T(华氏度)=(T(摄氏度)*9/5)+32

示例

输出

Temperature value in degree Celsius:  34
The 34.00 degree Celsius is equal to: 93.20 Fahrenheit
----OR----
Temperature value in degree Celsius:  23
The 23.00 degree Celsius is equal to: 73.40 Fahrenheit

将华氏度转换为摄氏度

用户可以使用以下公式将华氏度转换为摄氏度

Python program to convert Celsius to Fahrenheit

示例

输出

Temperature value in degree Fahrenheit:  113
The 113.00-degree Fahrenheit is equal to: 45.00 Celsius
----OR----
Temperature value in degree Fahrenheit:  234
The 234.00-degree Fahrenheit is equal to: 112.22 Celsius

结论

在本教程中,我们讨论了如何编写 Python 程序来将华氏度转换为摄氏度,反之亦然。


下一个主题Python 显示日历