python中华氏温度与摄氏温度的转换代码
以下是将华氏温度转换为摄氏温度的Python代码:
def fahrenheit_to_celsius(fahrenheit):
celsius = (fahrenheit - 32) * 5/9
return celsius
fahrenheit = float(input("请输入华氏温度:"))
celsius = fahrenheit_to_celsius(fahrenheit)
print("摄氏温度为:", celsius)
以下是将摄氏温度转换为华氏温度的Python代码:
def celsius_to_fahrenheit(celsius):
fahrenheit = (celsius * 9/5) + 32
return fahrenheit
celsius = float(input("请输入摄氏温度:"))
fahrenheit = celsius_to_fahrenheit(celsius)
print("华氏温度为:", fahrenheit)
你可以根据需要选择其中一个代码块来使用。
原文地址: http://www.cveoy.top/t/topic/jgDq 著作权归作者所有。请勿转载和采集!