Convert Celsius to Fahrenheit in Python
F = C * 9/5 + 32. The parentheses are not optional in your head even if Python's precedence saves you.
BeginnerBasic Python ProgramsExample 10 of 25
convert-celsius-to-fahrenheit.py
1# Program to convert Celsius to Fahrenheit23celsius = float(input("Enter temperature in Celsius: "))45fahrenheit = (celsius * 9/5) + 3267print(celsius, "°C is equal to", fahrenheit, "°F")
Output
Enter temperature in Celsius: 25 25.0 °C is equal to 77.0 °F
In this one
- (C * 9/5) + 32, then check 25 → 77
- Python 3: 9/5 is 1.8, not 1
What's going on
F = C × 9/5 + 32. In code: (celsius * 9/5) + 32.
9/5 is 1.8 in Python 3. In Python 2 it was 1. If an old blog writes 9/5 with integers, they might be teaching the wrong century.
25°C → 77°F. That's the sanity check. If you get 57, you forgot the + 32.
After this program
If the idea is still fuzzy, read Day 1: Introduction to Python in the Python course. For a short check, try the Python quiz (300 questions). Stay with all 25 basic python programs, or see every topic on Python exercises.