Using the captured default
Input
(make_adder(5))()
Output
5
Calling the created adder without arguments returns the captured default (5).
Full lesson preview
Build a function factory that captures a default value and returns an adder using that default.
Problem statement
Task
Examples
Input
(make_adder(5))()
Output
5
Calling the created adder without arguments returns the captured default (5).
Input
(make_adder(5))(3)
Output
8
Calling the adder with 3 returns default + 3 = 8.
Input format
Output format
Constraints
Samples
Input
(lambda a,b: (a(), b(2)))(make_adder(1), make_adder(10))
Output
(1, 12)
Two different adders capture different defaults and behave independently.