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.
Now solve a similar question yourself
A new Python question every time, checked instantly.
