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.

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``````

You can find the video on YouTube as well- Convert Celsius to 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``````