What you'll build
Ask for a temperature in Celsius, print it in Fahrenheit. Then go the other way. Math and input and output, in twenty lines.
Requirements
The must-do parts. If any are missing, we'll ask you to take another pass.
- Ask the user for a temperature in Celsius and convert it with
float(). - Calculate Fahrenheit using the formula
F = C * 9 / 5 + 32and print a labelled line. - Ask whether they want to convert another value back to Celsius (yes/no). If yes, ask for a Fahrenheit number and print the Celsius result.
- Use a comment above each block explaining what it does.
Bonus, if you're feeling brave
- Round both temperatures to one decimal place.
- Reject negative temperatures below -273 with a friendly message (absolute zero).
Examples
What your program should look like when it runs. Lines starting with $ are typed by you; the rest is your program.
Example run
$ python temperature.py
Temperature in Celsius: 30
30.0°C = 86.0°F
Convert another value back to Celsius? (yes/no): yes
Temperature in Fahrenheit: 100
100.0°F = 37.78°CWhere to start
Copy this scaffold into a new file. You don't have to use it — it's just a friendly nudge.
temperature.py
# Temperature converter
celsius = float(input("Temperature in Celsius: "))
fahrenheit = celsius * 9 / 5 + 32
print(f"{celsius}°C = {fahrenheit}°F")
# TODO: ask if they want to go the other way and convert F back to CHow we'll grade it
Four checks, four points. Three or above is passing — we'll ask you to revise anything we can't tick.
| Check | What we look for | Pt |
|---|---|---|
| It runs | Celsius → Fahrenheit produces the right number for 100°C (212°F). | 1 |
| Math is honest | Conversion uses `* 9 / 5 + 32`, not a magic constant. | 1 |
| Goes both ways | Fahrenheit → Celsius branch is reachable and correct. | 1 |
| Output reads well | Lines are labelled and easy to scan. | 1 |