python温度单位转换器
时间: 2023-10-13 13:18:04 浏览: 69
以下是一个简单的 Python 温度单位转换器,可以将摄氏度、华氏度、开尔文等不同温度单位相互转换:
```python
def celsius_to_fahrenheit(celsius):
return (celsius * 9 / 5) + 32
def fahrenheit_to_celsius(fahrenheit):
return (fahrenheit - 32) * 5 / 9
def celsius_to_kelvin(celsius):
return celsius + 273.15
def kelvin_to_celsius(kelvin):
return kelvin - 273.15
def fahrenheit_to_kelvin(fahrenheit):
return (fahrenheit + 459.67) * 5 / 9
def kelvin_to_fahrenheit(kelvin):
return kelvin * 9 / 5 - 459.67
print(celsius_to_fahrenheit(30)) # 86.0
print(fahrenheit_to_celsius(86)) # 30.0
print(celsius_to_kelvin(30)) # 303.15
print(kelvin_to_celsius(303.15)) # 30.0
print(fahrenheit_to_kelvin(86)) # 303.15
print(kelvin_to_fahrenheit(303.15)) # 86.0
```
这个程序包含了 6 个函数,分别用于摄氏度和华氏度、摄氏度和开尔文、华氏度和开尔文之间的转换。通过调用这些函数,可以实现不同温度单位之间的转换。