Functions that use functions
Python · Unit 4: Functions
- Full plan
- Python
- 9 exercises
A function can call another one. That way each one does a single thing, and together they solve something bigger.
def greeting(name):
return "Hello, " + name
def welcome(name):
print(greeting(name))
print("Come on in")
welcome("Maya")Prints
Hello, Maya Come on in
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. Predict the output
What does this code print?
2. Complete the code
Fill in the blank so
passeduses the average of the two scores.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 a check of 300 plus a 20 % tip. Which line has the error?
6. Multiple choice
What does
count_evensdo?7. Put the lines in order
Put in order the program that works out 3 items at 20 plus 8 for shipping.
8. Find the case that fails
pay(total, age)should charge 50 less to anyone who is 65 or older. Which call makes it fail?9. 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.