Module 4 Assignment 2.2 Answer
2.2 Welcome User
Question
Write a Python program that:
- Prompts the user to enter their name.
- Displays a greeting message using their name.
- If the user enters Sarah, the expected output should be:
Hello Sarah
Correct Python Code
# Prompt user for input
name = input("Enter your name: ")
# Display output
print("Hello", name)
Expected Output
Enter your name: Sarah
Hello Sarah
Explanation
- Prompt the user to enter their name using
input()
. - Store the input in the variable
name
. - Print the greeting message using
print("Hello", name)
. - When Sarah is entered, the output matches the expected result.
Why This Code is Correct
✅ Uses input()
to collect user input.
✅ Displays dynamic output based on the name entered.
✅ Matches the expected exam format perfectly!