Greet user by name and age with Python

Report a typo

You are writing a basic Python program that accepts user's name and age as inputs then prints hello message. The greeting message should be in the format Hello {name}, you are {age} years old!. Fill the blanks in the given code to make the function work as described.

You don't yet know how this code works, but you can guess based on your understanding of English.

To explain what particular parts of the code are for we use #comments. Everything after the hash up to the end of the line is regarded as a comment and will be ignored when running the code.

Fill in the gaps with the relevant elements
# Prompts for user's name and age
name = ("Please enter your name: ")
age = (input("Please enter your age: "))

# Defines a function that formats the message
def greeting(name, age):
    return f"Hello {name}, you are {age} years old!"

# Calls the function and prints out the formatted message
(greeting(name, age))
printinputint
___

Create a free account to access the full topic