Project: Temperature converter
Converting Celsius to Fahrenheit: F = C × 9 / 5 + 32.
Real programs get numbers as text from the user, so read them with input() and cast with float().
See it run
typed = "150" # in the lesson: typed = input("Pounds: ") pounds = float(typed) kg = pounds * 0.4536 print(round(kg, 1))
A converter is a small pipeline: text in, number, formula, tidy output. Follow the value along.
Practice project: temperature converter
Exercise 1
The user types 37. Store it as a float in celsius, compute fahrenheit, and print it rounded to 1 decimal (98.6).
Exercise 2
Now go the other way: C = (F − 32) × 5 / 9.
The user types 212. Store it as a float in fahrenheit, compute celsius, and print it rounded to 1 decimal (100.0).
Exercise 3
A weather app reads the morning and afternoon temperature in °C (the user types 18 then 26). Read them as floats named morning and afternoon, in that order.
- avg_f = the average of the two, converted to °F (71.6)
- rise_f = how many °F warmer the afternoon is (14.4)
Print both rounded to 1 decimal.
Free lesson: use the editor to practice it.
Practice
Loading Python…Visualizer Watch your code run line by line
Run your code, then choose Play to follow its execution.