[英]How do I get this Fahrenheit to Celsius Code in Python to return a value instead of the formula?
def c_to_f ():
c_temp= float(input("Enter temperature in Celsius to convert to Fahrenheit"))
f_temp= float(1.8 *c_temp) + 32
c_to_f()
print("The value in Fahrenheit is: " + f_temp)
The output***:输出***:
Enter temperature in Celsius to convert to Fahrenheit56
The value in Fahrenheit is: float(1.8 * c_temp) + 32
You have to return the created function object first:您必须先返回创建的 function object :
def c_to_f ():
c_temp= float(input("Enter temperature in Celsius to convert to Fahrenheit"))
f_temp= float(1.8 *c_temp) + 32
return f_temp
a = c_to_f()
# Return the object as string
print("The value in Fahrenheit is: " + str(a))
# Using printf
print(f"The value in Fahrenheit is: {a}")
Enter temperature in Celsius to convert to Fahrenheit34
The value in Fahrenheit is: 93.2
The value in Fahrenheit is: 93.2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.