输入摄氏温度,输出华氏温度
时间: 2023-05-31 09:07:00 浏览: 65
以下是Python的代码实现:
```python
celsius = float(input("请输入摄氏温度:"))
fahrenheit = (celsius * 1.8) + 32
print("华氏温度为:", fahrenheit)
```
首先,我们使用`float(input())`函数从用户那里获取摄氏温度,并将其转换为浮点数类型。接下来,我们将摄氏温度转换为华氏温度,公式为`F = C × 1.8 + 32`。最后,我们使用`print()`函数输出华氏温度。
相关问题
用c语言输入摄氏温度输出华氏温度
```
#include <stdio.h>
int main() {
float celsius, fahrenheit;
printf("请输入摄氏温度:");
scanf("%f", &celsius);
fahrenheit = celsius * 1.8 + 32;
printf("华氏温度为:%.2f\n", fahrenheit);
return 0;
}
```
python编写函数,输入摄氏温度输出华氏温度
可以使用下面的代码实现这个函数:
```python
def celsius_to_fahrenheit(celsius):
"""
将摄氏温度转换为华氏温度
"""
fahrenheit = celsius * 1.8 + 32
return fahrenheit
```
使用方法:
```python
>>> celsius_to_fahrenheit(0)
32.0
>>> celsius_to_fahrenheit(100)
212.0
>>> celsius_to_fahrenheit(-40)
-40.0
```
其中,摄氏温度为 `celsius`,华氏温度为 `fahrenheit`。