Python Program to Convert Celsius to Fahrenheit

In every science lecture, you must learn how to use and interpret the Celsius temperature scale. Before we explain how to convert Celsius to Fahrenheit, let’s review the main differences between the two temperature scales.

Celsius (written as °C and also called Centigrade) is the most common temperature scale in the world, used by all but five countries. It’s part of the International System of Units (SI), which is typically used in science classes (think centimeters, meters, kilograms, milliliters, etc.) and in science as a whole.

Fahrenheit is not part of the metric system; rather, it’s part of the Imperial system, which includes forms of measurements such as inches, feet, pounds, gallons, etc. Moreover, unlike Celsius, it is not typically used in science.

Celsius and Fahrenheit definition

The Celsius temperature range was originally defined by setting zero as the temperature at which water froze. Zero degrees C was later redefined as the temperature at which ice melts. The other point at which Celsius was set – 100 degrees Celsius – was defined as the boiling point of water.

The Fahrenheit temperature range is based on setting the freezing point of water at 32 degrees and boiling to 212 degrees. This means that boiling and freezing points are 180 degrees apart. Absolute zero is defined as -459.67°F.

For all the practice Videos and Explanations on Python, Check out Python Programming Exercises and Solutions.

Video Explanation to Convert Celsius to Fahrenheit in Python

Python Program to Convert Celsius To Fahrenheit

Celsius to Fahrenheit Formula

Converting from Celsius to Fahrenheit isn’t easy to do quickly or in your head. Here are the formulas used to convert Celsius to Fahrenheit. These formulas will give you the exact conversion from one unit of temperature to the other. To convert temperatures in degrees Celsius to Fahrenheit, multiply by 1.8 (or 9/5) and add 32.

°F =  (°C * 1.8 ) + 32 Or °F =  (°C * 9/5 ) + 32

For example, say the temperature outside is 18 °C, and you want to know what this would equal in Fahrenheit. Here’s how your equation would look once you plug in 18 for °C:

= (18 * 1.8) + 32

= (32.4) + 32

= 64.4 °F

tc = float(input("Enter temperature in degree celsius:"))
tf = tc * 9/5 + 32
print("Temperature in degree Celsius", tc,"is equal to",tf,"Fahrenheit")

In this program, the very first line accepts temperature in celsius from the user and then we convert that into afloat, and we store this in variable ‘tc’. In the next line, we have started doing calculations here; we have applied a formula for converting Celsius to Fahrenheit.

Here we are storing the result of the formula into tf variable and as per formula tc, which is the temperature in celsius into 9/5 or you can use 1.8 and add 32 in it. In the next line, we have written a print statement with a message and the result of the conversion. If you run this program, it prompts you to enter degree Celsius; let’s enter 36. You will get an output of 96.8 with the proper message.

Output:
Enter temperature in degree celsius:36
Temperature in degree Celsius 36.0 is equal to 96.8 Fahrenheit

Python Program to Convert Fahrenheit to Celsius

Fahrenheit to Celsius Formula

Here’s another example if you want to convert Fahrenheit to Celsius: say you’re feeling ill and your body temperature is 101.3 °F. To find out what this equals in Celsius, simply plug 101.3 into the °F part in the second equation written above:

°C =  (°F – 32 )  /  1.8 OR °C =  (°F – 32 ) *  5/9

= (101.3 – 32) / 1.8

= (69.3) / 1.8

= 38.5 °C

fahrenheit = float(input("Enter temperature in fahrenheit: "))
celsius = (fahrenheit - 32) * 5/9
print('%.2f Fahrenheit is: %0.2f Celsius' %(fahrenheit, celsius))

In the above program, the user enters the temperature, and we have converted it into float and stored it in Fahrenheit. Then we will move towards the conversion part; here we have calculated the celsius degree from Fahrenheit.

Here we will do Fahrenheit minus 32, and the whole value is multiplied by 5/9, and the result is stored into a celsius variable. In the next line, we have written a print statement with a message and the result of the conversion.

If you run this program, it prompts you to enter degree Celsius; let’s enter 96.8. You will get an output of 36 with the proper message. I am sure you know you have enough knowledge of converting Celsius into Fahrenheit and vice versa.

Output
Enter temperature in fahrenheit: 96.8
96.80 Fahrenheit is: 36.00 Celsius

About The Author