Python Functions
💡
Exercise 31

Temp Converter 15 XP Easy

Ctrl+Enter Run Ctrl+S Save

Let's revisit temperature conversion, but this time with functions!

The formulas:

  • Fahrenheit to Celsius: `(F - 32) / 1.8`
  • Celsius to Fahrenheit: `C * 1.8 + 32`

The round() function rounds a number:

print(round(3.14159, 2)) # 3.14
📋 Instructions
Create two functions: 1. `to_celsius(f)` — converts Fahrenheit to Celsius 2. `to_fahrenheit(c)` — converts Celsius to Fahrenheit Both should return rounded results (1 decimal place). Test them: ```python print(to_celsius(98.6)) print(to_fahrenheit(0)) print(to_fahrenheit(100)) ``` Expected output: ``` 37.0 32.0 212.0 ```
Use round((f - 32) / 1.8, 1) and round(c * 1.8 + 32, 1). You've got this — take it step by step!
⚠️ Try solving it yourself first — you'll learn more!
print(round(3.14159, 2))  # 3.14
🧪 Test Cases
Input
Run your code
Expected
37.0 32.0 212.0
Expected program output
main.py
Hi! I'm Rex 👋
Output
Ready. Press ▶ Run or Ctrl+Enter.