Loading exercise...

Exercise: Make a Greeter

Avatar image for Roetner

Roetner on July 4, 2026

Hi,

I wrote this as my solution, because I thought the inner function needs the greeting as well.

def say_greeting(greeting, name):
        return f'{greeting}, {name}!'

    return say_greeting

The hint in the test was for me misleading:

Signature mismatch: wrong number of arguments.

make_greeter.<locals>.say_greeting() missing 1 required positional argument: 'name'

Hint: The returned function should return '{greeting}, {name}!'

Because the return value is the right answer. Maybe you can change it?

Avatar image for Bartosz Zaczyński

Bartosz Zaczyński RP Team on July 5, 2026

@Roetner, your f-string is correct. f'{greeting}, {name}!' produces exactly the output the exercise wants, so that part isn’t the problem.

The catch is the signature of the inner function. This exercise is really about closures, which is the idea the later decorator lessons build on. The point is that say_greeting() should capture greeting from the enclosing make_greeter() scope instead of taking it as its own parameter. So the inner function only needs one argument, name:

def make_greeter(greeting):
    def say_greeting(name):
        return f"{greeting}, {name}!"
    return say_greeting

Here, say_greeting() never receives greeting directly. It reaches out to the greeting that belongs to make_greeter(), and that is what makes it a closure.

That also explains the test error. The checker uses your greeter the way a closure is meant to be used:

greet = make_greeter("Hello")
greet("World")

The second call passes a single argument, so with your two-parameter version Python assigns "World" to greeting and then reports name as missing. Same output string, wrong number of parameters.

If you want a refresher on why the inner function can see greeting without being handed it, Returning Functions From Functions and Inner Functions cover exactly that.

Avatar image for Roetner

Roetner on July 5, 2026

Hi Bartosz,

thanks for your quick and detailed reply. Now it is more clear to me.

Happy to be a part of RP :).

Best regards Roetner

Become a Member to join the conversation.