Python Program to Convert Celsius to Fahrenheit
easyInput and operatorsPython
A formula program that also teaches something important about Python 3: the / operator always gives a decimal answer.
The question
Read a temperature in Celsius (an integer) and print it in Fahrenheit using F = C × 9 / 5 + 32.
The code
Input
70
Output
Fahrenheit = 158.0
How it works
- 1Read the temperature in Celsius.
- 2Apply F = C × 9 / 5 + 32. Multiplication and division happen before addition.
- 3Because / produces a float, a whole answer such as 212 prints as 212.0.
Common mistakes
- Writing C * (9 / 5 + 32) — the brackets change the order and the answer is wrong.
- Using // (floor division), which throws away the decimal part.
Fahrenheit to Celsius (the reverse)
Turn the formula around: subtract 32 first, then multiply by 5 / 9. The brackets make the subtraction happen first.
Input
212
Output
Celsius = 100.0
Print a Celsius to Fahrenheit table using a loop
range(0, 101, 20) gives 0, 20, 40 … 100, and the same formula is applied to each value.
Input
(no input)
Output
0 C = 32.0 F 20 C = 68.0 F 40 C = 104.0 F 60 C = 140.0 F 80 C = 176.0 F 100 C = 212.0 F
Questions students ask
- What is the formula to convert Celsius to Fahrenheit in Python?
- f = c * 9 / 5 + 32. For 100 °C it gives 212.0 °F, and for 0 °C it gives 32.0 °F.
- How do I convert Fahrenheit to Celsius?
- c = (f - 32) * 5 / 9. Subtract 32 first — that is what the brackets are for — then multiply by 5 / 9. For 212 °F it gives 100.0 °C.
Now solve a similar question yourself
A new Python question every time, checked instantly.
Preparing for NIELIT O Level?
This program is the kind asked in the M3 (Python) theory paper and the PR-3 practical exam.
