Write a program in Python to convert Celsius into Fahrenheit and vice versa.

First, we need to take input the celsius and use the following formula to convert it into Fahrenheit.

fahrenheit = (9/5)*celsius + 32

So let’s see the source code of the same.

#input celcius
celsius = float(input("Enter Celcius: "))

#calculate fahrenheit using the formula
fahrenheit = (9/5)*celsius + 32
print("Fahrenheit ",fahrenheit)

Output

Enter Celcius: 37.5
Fahrenheit 99.5

Now let’s convert Fahrenheit back to Celsius by using the following formula.

celsius = (5/9)*(fahrenheit - 32)

Following is the python source code to convert Fahrenheit to Celsius.

#input fahrenheit
fahrenheit = float(input("Enter Fahrenheit: "))

celsius = (5/9)*(fahrenheit - 32)
print("Celsius ",celsius)

Output

Enter Fahrenheit: 99.5
Celsius 37.5

If you have any suggestion or doubts then comment below.

Leave a Reply