Python Program to Convert Celsius to Fahrenheit
Beginner · Basics
Celsius and Fahrenheit are two scales for measuring temperature: water freezes at 0°C or 32°F and boils at 100°C or 212°F. To convert, multiply the Celsius value by 9/5 and add 32. This program converts normal body temperature, 37°C, to Fahrenheit.
Program
37°C = 98.6°F
How it works
celsius * 9 / 5scales the value, since a change of 1 degree Celsius equals 1.8 degrees Fahrenheit.- Adding 32 shifts the scale, because 0°C is 32°F.
:.1fprints the result with one decimal place, giving 98.6.
Other ways to write it
A conversion table
Celsius Fahrenheit
-10 14.0
0 32.0
10 50.0
20 68.0
30 86.0
40 104.0range(-10, 41, 10) counts from -10 to 40 in steps of 10, and the widths in the f-string line up the columns.
Fahrenheit to Celsius
98.6°F = 37.0°C
To go the other way, subtract 32 first, then multiply by 5/9.
Try it yourself
Find the temperature where Celsius and Fahrenheit show the same number by trying values from -50 to 0 in a loop.
Edit the program above and press Run, or open it in the full editor to save it and share it. To watch it run line by line, open it in the visualizer.
Related programs
All Python programs · CBSE class 12 practical file · Python exercises