Script Valley
Python: Complete Language Course
Functions and Functional Patterns/Assessment

Practice & Assessment

Test your understanding of Functions and Functional Patterns

Multiple Choice Questions

5
1

What is the output of calling `broken()` twice, where `broken` uses a mutable default `items=[]` and appends 1 each call?

2

What does `*args` collect inside a function?

3

What does `nonlocal` do in Python?

4

What is the correct argument order in a Python function signature?

5

Why should you use `@functools.wraps(func)` in a decorator?

Coding Challenges

1
1

Timing decorator

Write a decorator called `timer` that measures and prints the execution time of any function it decorates. Use `time.perf_counter()` for measurement. The decorator must preserve the original function's name and return value. Test it on a function that sums numbers in a range. Input: any callable. Output: prints 'func_name ran in X.XXXXXX seconds', returns original result. Estimated time: 20-25 minutes.

Medium

Mini Project

1

Configurable Pipeline Runner

Build a data transformation pipeline using closures and decorators. Create a `Pipeline` class (or factory function) that accepts a list of transformation functions. Each step receives the output of the previous step. Add a `@log_step` decorator that prints the step name and output at each stage. Include a `@validate` decorator that checks the output is not None or empty before passing it forward. Test the pipeline with string transformations: strip whitespace, convert to lowercase, split into words, filter short words. All concepts from the module โ€” closures, *args/**kwargs, lambdas, decorators, and functools.wraps โ€” must appear in the solution.

Medium
Practice & Assessment โ€” Functions and Functional Patterns โ€” Python: Complete Language Course โ€” Script Valley โ€” Script Valley