Python Program to Convert Fahrenheit to Celsius

In this post, we will learn how to convert Fahrenheit to Celsius using Python Programming language.

To convert the temperature from fahrenheit to celsius, follow the following steps: 

  1. Take the temperature in Fahrenheit and subtract 32.
  2. Multiply this number by 5.
  3. Divide this number by 9 to obtain the temperature in degree Celsius.
  • Celsius = (Fahrenheit – 32) * 5/9

We will be using the above formula in our program to convert Fahrenheit to Celsius.

So, without further ado, let’s begin this tutorial.

Python Program to Convert Fahrenheit to Celsius

# Python Program to Convert Fahrenheit to Celsius
fahrenheit = float(input("Enter the temperature in Fahrenheit: "))

# Conversion from Fahrenheit to Celsius
celsius = (fahrenheit - 32) * 5/9

# Printing Output
print("%.2f Fahrenheit = %.2f Celsius" %(fahrenheit, celsius))

Output

Enter the temperature in Fahrenheit: 95
95.00 Fahrenheit = 35.00 Celsius

How Does This Program Work ?

fahrenheit = float(input("Enter the temperature in fahrenheit: "))

The user is asked to enter the temperature in degree Fahrenheit.

# Conversion from Fahrenheit to Celsius
celsius = (fahrenheit - 32) * 5/9

We convert the temperature from degree Fahrenheit to degree Celsius using the formula Celsius = (Fahrenheit – 32) * 5/9.

# Printing Output
print("%.2f Fahrenheit = %.2f Celsius" %(fahrenheit, celsius))

Finally, the result is displayed on the screen using print() function.

Python Program to Convert Fahrenheit to Celsius Using Functions

# Python Program to Convert Fahrenheit to Celsius Using Functions
def fahrenheit_to_celsius(fahrenheit):
    C = (fahrenheit - 32) * 5/9
    return C
    
# Asking for input
fahrenheit = float(input("Enter the temperature in Fahrenheit: "))

# Calling the function
celsius = fahrenheit_to_celsius(fahrenheit)

# Displaying output
print("%.2f Fahrenheit = %.2f Celsius" %(fahrenheit, celsius))

Output

Enter the temperature in Fahrenheit: 99.6
99.60 Fahrenheit = 37.56 Celsius
def fahrenheit_to_celsius(fahrenheit):
    C = (fahrenheit - 32) * 5/9
    return C

In this program, we have declared a custom function named fahrenheit_to_celsius which returns the temperature in degrees Celsius.

Conclusion

I hope after going through this post, you understand how to convert degree Fahrenheit to degree Celsius using Python Programming language.

If you have any doubt regarding the program, feel free to contact us in the comment section. We will be delighted to solve your query.

Also Read:

Leave a Comment

Your email address will not be published. Required fields are marked *