Parameters
Python · Unit 4: Functions
- Full plan
- Python
- 10 exercises
A parameter is a variable the function receives when you call it. If there are several, commas separate them.
The value you pass in the call is called an argument.
def area(base, height):
return base * height
print(area(4, 3))Prints
12
The rest of the explanation is in the lesson, which is part of the full plan.
Exercises in this lesson
You do them in the app, which checks them on the spot and explains why.
1. Complete the code
Fill in the call to work out the area of a 5 by 2 rectangle.
2. Multiple choice
In
def total(price, quantity):, what arepriceandquantity?3. Predict the output
What does this code print?
4. Predict the output
What does this code print?
5. Find the bug
This program should print what 3 coffees at 4 cost. Which line has the error?
6. Predict the output
What does this code print?
7. Complete the code
Fill in the blank so it prints "Ava is from Austin".
8. Find the case that fails
fits(width, space)should giveTrueif a couch fits in the space, including when it measures exactly the same. Which call makes it fail?9. Put the lines in order
Put in order the function that splits a 200 check among 4 people.
10. Predict the output
What does this code print?
It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.