Python is not only powerful but also a lot of fun—especially when you’re just getting started. One of the first exciting things you can try is making your program interact with users by asking them for input.
Let’s begin with a simple example where we ask for a user’s name and age using Python’s input()
function.
Example Code
name = input("What is your name?: ")
print(name)
age = input("How old are you?: ")
print(age)
Sample Output
What is your name?: Xayah
Xayah
How old are you?: 19
19
As you can see, the input()
function pauses the program and waits for the user to type something. Once the user provides input, Python stores it as a string.
Making It More Engaging
Now, instead of printing the name and age separately, let’s display everything neatly in one complete sentence.
Here’s how you can update the code:
Updated Code
name = input("What is your name?: ")
age = input("Enter your age: ")
print(name, "is", age, "years old.")
Updated Output
What is your name?: Xayah
Enter your age: 19
Xayah is 19 years old.
Final Thoughts
And that’s it! With just a few lines of code, you have created your very first interactive Python program.
Feel free to experiment by changing the prompts or modifying the final message. Playing around like this is one of the best ways to learn and get comfortable with coding in Python.