On Day 5 of my 100 Days of Python challenge,I explored user input.
This is where Python becomes more interactive instead of just printing things,it can now ask the user for information and respond to it.
Here’s the code I wrote today:
# Asking for user input
name = input("What is your name? ")
age = input("How old are you? ")
language = input("What programming language are you learning? ")
print("Hello", name + "!")
print("You are", age, "years old.")
print("It's great that you're learning", language + "!")
What happened when I ran it?
The input() function:
-Waits for the user to type something.
-Returns it as a string (even if you type a number).
-You can then store it in a variable and use it in your program.
GitHub update:
I saved my file as day5(user_input).py, then pushed it with:
git add 'day5(user_input).py'
git commit -m "user input"
git push
Challenge for you
Ask the user for their favorite food,favorite color and favorite hobby.
Print out a fun sentence using all three answers.
Your turn:
If you could make Python ask YOU one question, what would it be? Drop your answers in the comments I had love to see the creative ones!
Top comments (0)