Editor

A List of Multipliers

#596 · Functions · Intermediate · Review the AI's code · 70 XP · about 10 min

Someone asked an AI assistant: "Write a function that returns a list of n functions, where the first multiplies its argument by 1, the second by 2, and so on." This is its answer. It looks right, but it has a bug.

make_multipliers(n) should return a list of n functions. The function at index k takes one number and returns it multiplied by k + 1. With n equal to 0 the list is empty.

Examples

fs = make_multipliers(3)
fs[0](10)            # returns 10
fs[1](10)            # returns 20
fs[2](10)            # returns 30
[f(5) for f in fs]   # gives [5, 10, 15]

Constraints

  • 0 <= n <= 100

Fastest solvers

Leaderboard

First solves only, ranked by stars and then time.