Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Generate Personalized Greeters

Learn to build simple function factories using closures that produce customized greeting functions.

Python practice10 minClosures & Function FactoriesBeginnerLast updated April 13, 2026

Problem statement

Write a function make_greeter(greeting, punctuation='!') that returns a new function. The returned function should accept a single parameter name (string) and return a greeting string formatted as "{greeting}, {name}{punctuation}". The inner function must capture the values of greeting and punctuation from the enclosing scope (closure).

Task

Implement a closure that captures configuration (greeting and punctuation) and returns a reusable greeter function.

Examples

Basic greeter

Input

make_greeter("Hello")("Alice")

Output

Hello, Alice!

make_greeter captures 'Hello' and uses the default punctuation '!' to greet Alice.

Input format

A call expression: make_greeter(greeting, punctuation)(name).

Output format

A single string with the formatted greeting.

Constraints

greeting and punctuation are strings. name is a string. The returned value must be a string formatted exactly as described.

Samples

Sample 1

Input

make_greeter("Hi", "?")("Sam")

Output

Hi, Sam?

Custom punctuation '?' is used.