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)
你可以根据需要选择其中一个代码块来使用。
原文地址: https://www.cveoy.top/t/topic/ck8x 著作权归作者所有。请勿转载和采集!