Task: Python Temperature Conversion Program
Today, we will learn how to write Python programs to
1. Convert Fahrenheit to Celsius
2. Convert Celsius To Fahrenheit.
We will use the following temperature conversion formula:
Celsius To Fahrenheit and Fahrenheit to Celsius conversion formulas
Python Temperature Conversion Program
Celsius and Fahrenheit are the measurement units of Temperature. Let’s see the conversion formulas to convert temperature in degree Celsius to degree Fahrenheit and vice versa.
Here is the formula to convert C to F:
Fahrenheit to Celsius conversion formula
Fahrenheit = (Celsius * 9/5) + 32
Here is the required temperature conversion formula
Celsius To Fahrenheit Temperature Conversion Formula
Celsius = (Fahrenheit – 32) * 5/9
Python Program to Convert Fahrenheit to Celsius
In the following Python program example, first of all the user will enter a temperature in Fahrenheit and the program will convert this value to Celsius using the Fahrenheit to Celsius formula. Finally this program will output the result that is temperature in celsius.
# Python Program Temperature Conversion F to C fahrenheit = float(input("Enter temperature in fahrenheit: ")) celsius = (fahrenheit - 32) * 5/9 celsius = round(celsius,2) print(fahrenheit,' Fahrenheit is = ', celsius,' Celsius')
Python Program to Convert Celsius To Fahrenheit
In this Python program example, first of all the user will enter a temperature in Celsius and the program will convert this value to Fahrenheit using the Celsius to Fahrenheit formula. Finally this program will output the result that is temperature in Fahrenheit.
# Python Program to Convert Celsius To Fahrenheit celsius = float(input("Enter temperature in celsius: ")) fahrenheit = (celsius * 9/5) + 32 fahrenheit = round(fahrenheit,2) print(celsius,' Celsius is:', fahrenheit,' Fahrenheit')
Output of Python Temperature Conversion Program
Enter temperature in celsius: 37
37.0 Celsius is: 98.6 Fahrenheit
Enter temperature in fahrenheit: 98.6
98.6 Fahrenheit is = 37.0 Celsius
Find Average Temperature of Week