Chapters
Python114 chapters

Exercises

Arguments

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

Exercise 1

Call describe with keyword arguments so the order does not matter.

Python
def describe(name, age):
    print(f"{name} is {age}")

# call it with age first, by name
Exercise 2

Fix the shared default so each call starts with an empty list.

Python
def add(item, target=[]):
    target.append(item)
    return target

print(add("a"))
print(add("b"))
Exercise 3

Call describe by unpacking the dictionary into keyword arguments.

Python
def describe(name, age):
    print(f"{name} is {age}")

details = {"name": "Grace", "age": 45}
# call describe using details