- Read the question carefully (twice).
- Break the task into the smallest steps.
- Sketch or write pseudocode before coding.
- Start small — test as you go.
- Check your solution with different cases.
Problem Description
Scientists, engineers, and everyday people often need to switch between different temperature scales:
- Celsius (°C) is used in most of the world.
- Fahrenheit (°F) is common in the United States.
- Kelvin (K) is used in science (with no negative numbers).
Your task is to write a program that converts temperatures between Celsius, Fahrenheit, and Kelvin.
Learning Goals
By completing this problem, you should be able to:
- Work with mathematical formulas in code.
- Write and use functions to organize your program.
- Apply user input and output.
- Test your program with different values.
Conversion Formulas
You will need these formulas:
- Celsius → Fahrenheit:
- Fahrenheit → Celsius:
- Celsius → Kelvin:
- Kelvin → Celsius:
- (You can combine formulas to go Fahrenheit → Kelvin or Kelvin → Fahrenheit.)
Tasks
Task 1: Convert Celsius → Fahrenheit
Write a program that:
- Asks the user to enter a temperature in Celsius.
- Converts it to Fahrenheit.
- Prints the result.
Task 2: Convert Fahrenheit → Celsius
Expand your program:
- Asks the user for a temperature in Fahrenheit.
- Converts it to Celsius.
- Prints the result.
Task 3: Add Kelvin
Update your program so it can handle all three scales:
- Celsius ⇄ Fahrenheit
- Celsius ⇄ Kelvin
- Fahrenheit ⇄ Kelvin
(Hint: You don’t need to memorize new formulas—use Celsius as a “middle step.”)
Task 4: User Chooses Conversion
Modify your program to:
- Ask the user which conversion they want (for example,
"C to F","F to C","C to K","K to F", etc.). - Perform the correct calculation.
- Print the result clearly, including the unit.
Task 5: Test Cases
Test your program with the following inputs. Write down what your program prints:
0°C→ Fahrenheit → Expected:32°F100°C→ Fahrenheit → Expected:212°F-40°C→ Fahrenheit → Expected:-40°F0 K→ Celsius → Expected:-273.15°C32°F→ Celsius → Expected:0°C300 K→ Fahrenheit → Expected:80.33°F(approx.)
Extension Challenge (Optional)
Improve your program so that:
- It keeps running in a loop until the user chooses to quit.
- It rejects impossible values (for example, temperatures below 0 K).
- It rounds results to 2 decimal places.
✅ Success Criteria:
- You can convert between Celsius, Fahrenheit, and Kelvin.
- Your program handles multiple types of conversions correctly.
- Your program works with the test cases provided.