python / beginner
Snippet
Getting User Input
The input() function allows a program to pause and wait for the user to type something. It always returns the input as a string.
snippet.py
1
2
user_name = input("Enter your name: ")print("Hello, " + user_name)
Breakdown
1
user_name = input("Enter your name: ")
Displays a prompt and stores the user's typed response in a variable.
2
print("Hello, " + user_name)
Joins the greeting with the stored name and prints it.