Basic multipliers
Input
funcs = generate_multipliers([1, 2, 3]) funcs[1](5)
Output
10
The second generated function multiplies by 2, so funcs[1](5) returns 10.
Full lesson preview
Learn to build function factories that correctly capture loop variables. Fix the common late-binding bug when creating functions inside loops.
Problem statement
Task
Examples
Input
funcs = generate_multipliers([1, 2, 3]) funcs[1](5)
Output
10
The second generated function multiplies by 2, so funcs[1](5) returns 10.
Input format
Output format
Constraints
Samples
Input
generate_multipliers([2, 3, 5])[2](4)
Output
20
The third function multiplies by 5, so passing 4 returns 20.