Area of a Rectangle
Beginner · 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 area that takes width and height as parameters and returns their product (the area of a rectangle). Do not print - just return the value.
# Define your function here
# Test it
print(area(5, 3))
print(area(10, 7))
What Check runs
Your code runs first, then each of these lines. The output must match exactly.
| Runs | Expected output |
|---|---|
| print(area(5, 3)) | 15 |
| print(area(10, 7)) | 70 |
| print(area(1, 1)) | 1 |
More Function exercises
- Say HelloBeginner
- Predict the OutputBeginner
- Fix the Broken FunctionIntermediate
- Temperature ConverterIntermediate
- Build a Grade CalculatorAdvanced
All Python exercises · 50 practice problems · Functions quiz