Skip to the content

Functions that use functions

Python · Unit 4: Functions

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. 1. Predict the output

    What does this code print?

  2. 2. Complete the code

    Fill in the blank so passed uses the average of the two scores.

  3. 3. Predict the output

    What does this code print?

  4. 4. Predict the output

    What does this code print?

  5. 5. Find the bug

    This program should print a check of 300 plus a 20 % tip. Which line has the error?

  6. 6. Multiple choice

    What does count_evens do?

  7. 7. Put the lines in order

    Put in order the program that works out 3 items at 20 plus 8 for shipping.

  8. 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. 9. Predict the output

    What does this code print?

Do this lesson

It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.

See all lessons →