华氏温度(F)与摄氏温度(C)的转换公式如下:

摄氏温度转换为华氏温度:F = C * 9/5 + 32

华氏温度转换为摄氏温度:C = (F - 32) * 5/9

以下是Python中的示例代码:

摄氏温度转换为华氏温度

def celsius_to_fahrenheit(celsius): fahrenheit = celsius * 9/5 + 32 return fahrenheit

华氏温度转换为摄氏温度

def fahrenheit_to_celsius(fahrenheit): celsius = (fahrenheit - 32) * 5/9 return celsius

示例用法

celsius = 25 fahrenheit = celsius_to_fahrenheit(celsius) print(f"{celsius}摄氏度 = {fahrenheit}华氏度")

fahrenheit = 77 celsius = fahrenheit_to_celsius(fahrenheit) print(f"{fahrenheit}华氏度 = {celsius}摄氏度")

python中华氏温度与摄氏温度的转换

原文地址: http://www.cveoy.top/t/topic/jgDp 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录