Temperature Converter
Intermediate · Write the code · from Python Functions: Define, Call, and Return Values
From the lesson: Python Functions: Define, Call, and Return Values
Imagine you have a favorite recipe for pancakes. Every Sunday morning, you follow the same steps: mix flour, crack eggs, pour batter, flip. You don't reinvent the recipe each time - you just follow the one you already know.
Read the lessonWrite a function called celsius_to_fahrenheit that takes a temperature in Celsius and returns it converted to Fahrenheit. The formula is: F = C * 9/5 + 32. Return the result as a float (the formula naturally produces one).
# Define your function here
# Test it
print(celsius_to_fahrenheit(0))
print(celsius_to_fahrenheit(100))
print(celsius_to_fahrenheit(37))
What Check runs
Your code runs first, then each of these lines. The output must match exactly.
| Runs | Expected output |
|---|---|
| print(celsius_to_fahrenheit(0)) | 32.0 |
| print(celsius_to_fahrenheit(100)) | 212.0 |
| print(celsius_to_fahrenheit(37)) | 98.6 |
More Function exercises
- Say HelloBeginner
- Predict the OutputBeginner
- Area of a RectangleBeginner
- Fix the Broken FunctionIntermediate
- Build a Grade CalculatorAdvanced
All Python exercises · 50 practice problems · Functions quiz