input(), explained simply
So far your programs talk, but they cannot listen. input() changes that. It shows a question, waits for the person to type something and press Enter, then hands back what they typed.
You usually store the answer in a variable so you can use it later: name = input("What is your name? ").
Whatever someone types comes back as text (a string), even if they type digits. You can join text together with + or, more easily, put it in an f-string.
Example: A talking ticket booth
name = input("What is your name? ")
place = input("Where are you going? ")
print("Ticket for " + name + " to " + place)Output
What is your name? Kabir
Where are you going? the lighthouse
Ticket for Kabir to the lighthouseThe words after each question are what the person typed.
Try this
- Ask for someone’s favourite colour and reply with a sentence that uses it.
- Leave out the spaces around the + signs in the text and see how the words squash together.
- Rewrite the last line using an f-string instead of +.
