Menu

Sign in to track your progress and unlock all features.

Theme style

Log in
01. Define a function that adds two numbersE02. Write a function that returns a greetingE03. Implement a function to find the maximum of threeE

Problem No 2

Write a function that returns a greeting

Easy

8 minute session

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.

Code editor
Loading editor…

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.

02:03 PM

Free preview includes 1 Teach Theory response and 1 AI hint on each of the first 3 lessons in this module.