A greeting program is a useful first interactive project because it combines keyboard input, a variable, and displayed output.
Understanding the Concept
The program asks for a name, receives a string, and builds a personalized message. Python input() always returns text, even when the person types digits. For names, that is exactly what you want. To keep the exercise simple, use .strip() to remove spaces accidentally typed at the beginning or end. There is no need for a database, web page, or external package.
When and Why You Would Use This
Plan the behavior before running it: prompt once, read the reply, and print a greeting. Try ordinary text, an empty response, and a name with leading spaces. A future lesson can add validation for empty input.
Practical Example
learner_name = input("Enter your name: ").strip()
print("Welcome to Python, " + learner_name + "!")
Understanding the Example
If the user enters Taylor, the output is Welcome to Python, Taylor! The strip() method returns a trimmed version of the text. The plus operator joins strings here; the variable holds text rather than a number.
Example Output
Enter your name: Welcome to Python, 24!
Try It Yourself
Change the prompt to ask for a favorite hobby and print a two-line message that includes both name and hobby.
Common Beginner Mistakes
- Forgetting that input waits for the user to press Enter.
- Using int() to convert a name. Names are strings, not numbers.
- Ignoring empty input and displaying a greeting with no name. Consider adding validation later.
Key Takeaways
- input() reads user-entered text.
- A variable can hold that text for later use.
- String methods can clean simple input before display.