Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Problem No 8

Format a String

Easy

10 minute session

Summary

Combine text and values into a single formatted string using Python strings.

Problem statement

Implement format_greeting(name, age) that returns a greeting sentence exactly in this format: Hello, {name}! You are {age} years old. The function should convert the age to text if necessary and insert the provided name and age into the template. Do not print; return the formatted string.

Task

Practice converting values to strings and using string formatting to produce a readable message.

Examples

Basic example

Input

format_greeting('Alice', 30)

Output

Hello, Alice! You are 30 years old.

Explanation

Name and numeric age are inserted into the template.

Input format

Two arguments: name (string) and age (any value convertible to string).

Output format

A single string matching the greeting template exactly.

Constraints

Return a string. Preserve the input values as-is when converting (no rounding unless Python's default str() does it).

Samples

Sample input 0

format_greeting('Bob', '25')

Sample output 0

Hello, Bob! You are 25 years old.

Explanation 0

Age provided as a string is placed into the template unchanged.

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.

03:38 AM

Free preview includes 1 Teach Theory response and 1 AI hint per unlocked preview lesson.