Problem No 2
Write a function that returns a greeting
Easy≈ 8 minute session
Lesson guide
What this Python exercise practices
Write a function that returns a greeting is a beginner practice lesson that focuses on functions, parameters, return values. It is designed to be solved in about 8 minutes with examples, starter code, and test feedback.
Prerequisites
- Python variables
- Function parameters
- Return values
Difficulty and time
- Level
- Beginner
- Estimated time
- 8 minutes
Practice path
Summary
Create a greeting function that returns a formatted hello message.
Problem statement
Write a function called greet that accepts a single string parameter name and returns the greeting string in the exact format: "Hello, {name}!". If name is an empty string, still return "Hello, !". Do not print; return the string.
Task
Implement greet(name) to return a friendly greeting string using the provided name.
Examples
Greet Alice
Input
greet("Alice")
Output
Hello, Alice!
Explanation
The function inserts the name into the greeting template.
Input format
Call the function as greet(name) where name is a string.
Output format
Return a string formatted as: Hello, {name}!
Constraints
The returned string must match the exact format, including punctuation and spacing.
Samples
Sample input 0
greet("Bob")
Sample output 0
Hello, Bob!
Explanation 0
Basic name greeting.
AI assistant
Ask me anything!
Need help? I can explain the core idea behind this problem, review your current code, and give targeted hints. Use “Teach Theory” for the concept, “Get AI hint” for a quick scaffold nudge, or ask a specific question below.
Chat history is temporary and will not be saved.
Free preview includes 1 Teach Theory response and 1 AI hint per unlocked preview lesson.