In this Python program, we will learn how to convert Celsius to Fahrenheit and Fahrenheit to Celsius.
For Converting Celsius to Fahrenheit, the formula is as:
celsius = (fahrenheit - 32) / 1.8
And for Converting Fahrenheit to Celsius, the formula is as:
fahrenheit = (celsius * 1.8) + 32
Here is the source code of the program to convert Celsius to Fahrenheit and Fahrenheit to Celsius.
# Python Program to convert temperature from celsius to fahrenheit
# change this value for a different result
celsius = 37.5
# calculate fahrenheit
fahrenheit = (celsius * 1.8) + 32
print('%0.1f degree Celsius is equal to %0.1f degree Fahrenheit' %(celsius,fahrenheit))
37.5 degree Celsius is equal to 99.5 degree Fahrenheit
# Program 2 - Python Program to convert temperature in Fahrenheit to Celsius
fahrenheit = 99.5
# calculate fahrenheit
celsius = (fahrenheit - 32) / 1.8
print('%0.1f degree Fahrenheit is equal to %0.1f degree Celsius' %(fahrenheit,celsius))
99.5 degree Fahrenheit is equal to 37.5 degree Celsius
Comments