Greeting with a Default
Beginner · Write the code · from Python *args, **kwargs, Default Values, and Keyword Arguments
From the lesson: Python *args, **kwargs, Default Values, and Keyword Arguments
Think about ordering coffee. You always need to pick a size - that's required. But extras like oat milk, an extra shot, or caramel drizzle? Those are optional. You only mention them when you want them.
Read the lessonWrite a function called greet that takes a name parameter and an optional greeting parameter with a default value of 'Hello'. It should print <greeting>, <name>!. For example, greet('Alice') prints Hello, Alice! and greet('Bob', 'Hey') prints Hey, Bob!.
# Define your function here
# Test it
greet('Alice')
greet('Bob', 'Hey')
What Check runs
Your code runs first, then each of these lines. The output must match exactly.
| Runs | Expected output |
|---|---|
| greet('Alice') | Hello, Alice! |
| greet('Bob', 'Hey') | Hey, Bob! |
| greet('Eve', 'Hi') | Hi, Eve! |
More Function Arguments exercises
- Predict the Keyword CallBeginner
- Sum All NumbersIntermediate
- Fix the Mutable DefaultIntermediate
- Build a Profile StringIntermediate
- Flexible CalculatorAdvanced
- Refactor to Use **kwargsAdvanced
All Python exercises · 50 practice problems · Functions quiz