In this tutorial, we will write Python programs to convert Celsius To Fahrenheit and Vice Versa.
Celsius To Fahrenheit and Fahrenheit to Celsius conversion formulas
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.
Celsius = (Fahrenheit – 32) * 5/9 Fahrenheit = (Celsius * 9/5) + 32
To understand the following programs, you must have the basic knowledge of following Python concepts:
1. Python Input/Output
2. Python Data Types
Program to Convert Celsius To Fahrenheit
In the following program we are taking the input from user, user enters the temperature in Celsius and the program converts the entered value into Fahrenheit using the conversion formula we have seen above.
celsius = float(input("Enter temperature in celsius: ")) fahrenheit = (celsius * 9/5) + 32 print('%.2f Celsius is: %0.2f Fahrenheit' %(celsius, fahrenheit))
Output:
Program to Convert Fahrenheit to Celsius
In the following program user enters the temperature in Fahrenheit and the program converts the entered value into Celsius using the Fahrenheit to Celsius conversion formula.
fahrenheit = float(input("Enter temperature in fahrenheit: ")) celsius = (fahrenheit - 32) * 5/9 print('%.2f Fahrenheit is: %0.2f Celsius' %(fahrenheit, celsius))
Output:
Leave a Reply