AssignmentsWeek 01 · FoundationsTemperature converter
wk01.p3Practice exerciseWeek 01 · FoundationsOpen · due in week 1

Temperature converter

Ask for a temperature in Celsius, print it in Fahrenheit. Then go the other way. Math and input and output, in twenty lines.

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.

  1. Ask the user for a temperature in Celsius and convert it with float().
  2. Calculate Fahrenheit using the formula F = C * 9 / 5 + 32 and print a labelled line.
  3. 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.
  4. 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°C

Where 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 C

How we'll grade it

Four checks, four points. Three or above is passing — we'll ask you to revise anything we can't tick.

CheckWhat we look forPt
It runsCelsius → Fahrenheit produces the right number for 100°C (212°F).1
Math is honestConversion uses `* 9 / 5 + 32`, not a magic constant.1
Goes both waysFahrenheit → Celsius branch is reachable and correct.1
Output reads wellLines are labelled and easy to scan.1
Ready?
Hand it in
You can submit a draft and revise later if you're not done.
Begin submission →