Python Program to convert Fahrenheit to Celsius
Python Program - Convert Fahrenheit to Celsius
To convert Fahrenheit to Celsius, you can use the following formula in the program.
Celsius = (Fahrenheit - 32) * 5 / 9
Let us write a function, that takes the Fahrenheit value as argument, computes the Celsius using the above formula, and return the result.
def fahrenheitToCelsius(f):
return (f - 32) * 5 / 9
You may use this function, in your program, to convert Fahrenheit to Celsius.
The following is an example program, where we shall use the above conversion function, and convert 98.6
Fahrenheit to Celsius and print the result to output.
Python Program
# Function that converts F to C
def fahrenheitToCelsius(f):
return (f - 32) * 5 / 9
if __name__ == "__main__":
# Given Fahrenheit
f = 98.6
# Convert Fahrenheit to Celsius
c = fahrenheitToCelsius(f)
print(f"{f} Fahrenheit is equal to {c} Celsius")
Output
98.6 Fahrenheit is equal to 37.0 Celsius
To implement the formula, we used Python Subtraction, Python Multiplication, and Python Division from Python Arithmetic Operators.
To verify your output, you can use this online tool: Convert Fahrenheit to Celsius online by ConvertOnline.org.