AlgoMaster Logo

Functional Programming - Quiz

Last Updated: December 6, 2025

Functional Programming Exercises

30 quizzes

1
Code Completion

Complete the code to apply a function to every element and build a new list of squares.

python
1
squared_values = list(map(, [1, 2, 3, 4]))

Click an option to fill the blank:

2
Code Completion

Complete the code so that the function reference, not its result, is stored for later use.

python
1
stored =

Click an option to fill the blank:

3
Code Completion

Complete the expression to convert an immutable list of scores into a new sorted list without changing the original.

python
1
sorted_scores = (scores)

Click an option to fill the blank:

4
Multiple Choice

In functional programming, what does it mean that functions are first-class citizens in Python?

5
Multiple Choice

Which property is essential for a function to be considered pure?

6
Multiple Choice

Which built-in function best represents a higher-order function?

7
Multiple Choice

You want to pre-fill some arguments of a function and get a new callable. Which tool should you use?

8
Multiple Choice

Currying transforms a function with multiple arguments into what?

9
Multiple Choice

Which Python type is immutable?

10
Multiple Choice

Why are pure functions easier to test?

11
Multiple Choice

Which statement about lambda functions is true?

12
Multiple Choice

You have an immutable configuration stored as a tuple of values. How do you update it functionally?

13
Multiple Choice

Which example best illustrates a higher-order function returning another function?

14
Sequencing

Order the steps to create and use a higher-order function that filters even numbers from a list.

Drag and drop to reorder, or use the arrows.

15
Sequencing

Order the steps to implement a curried adder that adds three numbers one by one.

Drag and drop to reorder, or use the arrows.

16
Output Prediction

What is the output of this code using a pure function to transform data?

1def double_price(price):
2    return price * 2
3
4prices = [10, 20, 30]
5new_prices = list(map(double_price, prices))
6print(new_prices[-1])
17
Output Prediction

What is the output when using filter with a lambda?

1numbers = [1, 2, 3, 4, 5]
2result = list(filter(lambda value: value > 3, numbers))
3print(len(result))
18
Output Prediction

What is the output when creating a partially applied function?

1from functools import partial
2
3def power(base, exponent):
4    return base ** exponent
5
6square = partial(power, exponent=2)
7print(square(5))
19
Output Prediction

What is the output of this curried multiplier example?

1def multiply_by(a):
2    def inner(b):
3        return a * b
4    return inner
5
6double = multiply_by(2)
7print(double(7))
20
Output Prediction

What is the output when working with an immutable string?

1title = "developer"
2new_title = title.upper()
3print(title == new_title)
21
Bug Spotting

This function is meant to be a pure function that applies a tax rate to a price list. Find the bug that breaks purity.

Click on the line(s) that contain the bug.

python
1
tax_rate = 0.2
2
 
3
def apply_tax(prices):
4
    taxed = []
5
    for price in prices:
6
        taxed_price = price + price * tax_rate
7
        prices.append(taxed_price)
8
        taxed.append(taxed_price)
9
    return taxed
22
Bug Spotting

This code aims to demonstrate immutability using a tuple of coordinates. Find the bug.

Click on the line(s) that contain the bug.

python
1
def move_point(point, dx, dy):
2
    # point is expected to be an (x, y) tuple
3
    point[0] = point[0] + dx
4
    point[1] = point[1] + dy
5
    return point
6
 
7
start = (0, 0)
8
end = move_point(start, 5, 3)
23
Matching

Match each functional programming concept with its description.

Click an item on the left, then click its match on the right. Click a matched item to unmatch.

24
Matching

Match each Python tool with how it supports functional programming.

Click an item on the left, then click its match on the right. Click a matched item to unmatch.

25
Fill in the Blanks

Complete the pure function that returns a new list of title-cased names without modifying the original list.

python
1
def normalize_names(raw_names):
2
clean_names =
3
for raw_name in raw_names:
4
clean_names.append()
5
return clean_names

Click an option to fill blank 1:

26
Fill in the Blanks

Complete the code to use a higher-order function that filters active users based on a predicate.

python
1
def is_active(user_record):
2
return user_record["active"]
3
4
users = [{"name": "A", "active": True}, {"name": "B", "active": False}]
5
active_users = list((, users))

Click an option to fill blank 1:

27
Fill in the Blanks

Complete the code to create a partial function that always calls the logging function with level='INFO'.

python
1
from functools import
2
3
def log(level, message):
4
return f"[{level}] {message}"
5
6
info_log = (log, level="INFO")

Click an option to fill blank 1:

28
Fill in the Blanks

Complete the code so that updating a configuration uses immutability by creating a new dict instead of changing the original.

python
1
def with_timeout(config, timeout_seconds):
2
new_config = (config)
3
new_config["timeout"] = timeout_seconds
4
return

Click an option to fill blank 1:

29
Hotspot Selection

Click the line that introduces a side effect and makes the function impure.

Click on the line to select.

python
1
log_messages = []
2
 
3
def compute_total(prices):
4
    total = sum(prices)
5
    log_messages.append(f"Computed total: {total}")
6
    return total
30
Hotspot Selection

Click the line that incorrectly attempts to mutate an immutable string.

Click on the line to select.

python
1
message = "hello"
2
chars = list(message)
3
chars[0] = 'H'
4
message = ''.join(chars)
5
print(message)

Premium Content

Subscribe to unlock full access to this content and more premium articles.