Chapters
Python114 chapters

Exercises

Functions

3 tasks. Write the code, press Check, and the page runs it against a real Python interpreter.

Exercise 1

Write a function called double that returns twice its argument, then print double(5).

Python
# define double, then print double(5)
Exercise 2

This prints but returns nothing, so result is None. Fix it.

Python
def double(n):
    print(n * 2)

result = double(5)
print(result + 1)
Exercise 3

Pass the shout function into apply_twice so it is applied twice to hey.

Python
def shout(word):
    return word.upper() + "!"

def apply_twice(fn, value):
    return fn(fn(value))

# call apply_twice with shout and "hey"