Python Program to Convert Celsius To Fahrenheit


Levels of difficulty: / perform operation:

Source Code:


# Python Program to convert temperature in celsius to fahrenheit 
# Input is provided by the user in degree celsius

# take input from the user
celsius = float(input('Enter degree Celsius: '))

# calculate fahrenheit
fahrenheit = (celsius * 1.8) + 32
print('%0.1f degree Celsius is equal to %0.1f degree Fahrenheit' %(celsius,fahrenheit))

Output:

Enter degree Celsius: 37.5
37.5 degree Celsius is equal to 99.5 degree Fahrenheit


Explanation

In this program, we ask the user for temperature in degree Celsius and convert it into degree Fahrenheit. They are related by the formula celsius * 1.8 = fahrenheit – 32. With a simple modification to this program, we can convert Fahrenheit into Celsius. We ask the user for temperature in Fahrenheit and use the following formula to convert it into Celsius.

celsius = (fahrenheit - 32) / 1.8