Code Logo

Reminder Message with Default Argument

Published at22 Apr 2026
Python Functions Easy 0 views
Like0

A school office sends short reminder messages to students before events. Most of the time the message starts with the same greeting, but sometimes the staff wants to pass in a different greeting for a special occasion.

Your task is to write a function that returns a string in the format "Greeting, Name!". The function should accept a student name and an optional greeting. If no greeting is provided, it should use "Hello" by default.

For example, calling the function with "Ayu" should return "Hello, Ayu!". Calling it with "Bima" and "Hi" should return "Hi, Bima!".

This challenge is less about string tricks and more about how Python functions can offer a sensible default value while still allowing callers to override it when needed. The output format should always include the greeting, a comma, a space, the name, and an exclamation mark.

Example Input & Output

Example 1
Input
name = "Cici", greeting = "Welcome"
Output
"Welcome, Cici!"
Explanation

Any custom greeting should be inserted into the final message.

Example 2
Input
name = "Bima", greeting = "Hi"
Output
"Hi, Bima!"
Explanation

A provided greeting replaces the default value.

Example 3
Input
name = "Ayu"
Output
"Hello, Ayu!"
Explanation

When no custom greeting is passed, the default greeting is used.

Algorithm Flow

Recommendation Algorithm Flow for Reminder Message with Default Argument
Recommendation Algorithm Flow for Reminder Message with Default Argument

Solution Approach

This problem is a straightforward introduction to default arguments in Python. A default argument lets the function work in two convenient ways: it can use a normal built-in value when the caller gives only the required input, and it can switch to a custom value when the caller passes an extra argument.

Here, the student name is always required, but the greeting is optional. That means the function header itself can carry the rule:

def build_reminder(name, greeting="Hello"):

When Python sees that definition, it knows to use "Hello" whenever no second argument is supplied. So a call like build_reminder("Ayu") automatically behaves as if the greeting had been passed explicitly.

After that, the body is just string formatting:

return f"{greeting}, {name}!"

This keeps the function easy to read because the default behavior is declared exactly where the parameter is introduced. There is no need for extra if checks inside the function just to decide whether a greeting exists.

The nice part of this pattern is that the function stays flexible. One caller can rely on the default and another caller can override it with something like "Hi" or "Welcome", while the rest of the logic stays unchanged.

For an easy Python Functions challenge, this is a good example of how a function signature can carry part of the behavior by design, instead of pushing all of the decision-making into the body.

Best Answers

python - Approach 1
def build_reminder(name, greeting="Hello"):
    return f"{greeting}, {name}!"