编写一个 Python 程序将摄氏度转换为华氏度。在看示例之前,我先向您展示将摄氏度转换为华氏度的数学公式是:华氏度 = (摄氏度 * 9/5) + 32。或者,您也可以用 1.8 替换 9/5。
此示例允许输入摄氏度温度,并使用上述数学公式将其转换为华氏度。
celsius = float(input("Please Enter the Temperature in Celsius = "))
fahrenheit = (1.8 * celsius) + 32
//fah = ((cel * 9)/5) + 32
print("%.2f Celsius Temperature = %.2f Fahrenheit" %(celsius, fahrenheit))

def ctof(c):
f = (c * 9/5) + 32
return f
c = float(input("Enter the Temperature in Celsius = "))
f = ctof(c)
print("%.2f Degrees Celsius Temperature = %.2f Fahrenheit" %(c, f))
Enter the Temperature in Celsius = 28
28.00 Degrees Celsius Temperature = 82.40 Fahrenheit