Editor

Default Parameters

Functions · Beginner · 35 XP · about 3 min

Write a function called greet_person(name, greeting="Hello") that creates a greeting message with an optional greeting word.

Example

greet_person("Alice")             # Returns "Hello, Alice!"
greet_person("Bob", "Hi")         # Returns "Hi, Bob!"
greet_person("Eve", "Welcome")    # Returns "Welcome, Eve!"

Requirements

  • The greeting parameter should default to "Hello"
  • Return a string in the format: "{greeting}, {name}!"
  • Include the comma and exclamation mark
def greet_person(name, greeting="Hello"):
# Your code here
pass
# Test your function
print(greet_person("Alice"))
print(greet_person("Bob", "Hi"))

Ready?

Accept the challenge to start writing. A small timer counts the time this page is in view.

Output appears here.