Talking with Your Program · practice
Ask More Than One Question
A program can call input() more than once. Each call pauses for one answer, then the program continues from the next line.
name = input("What is your name? ")
hobby = input("What do you enjoy? ")
Python asks the questions in order. The first answer is assigned to name. The second answer is assigned to hobby.
One Enter press answers one question
When you run the starter program:
Type an answer to the first question and press Enter.
Wait for the second question.
Type the second answer and press Enter again.
Do not type both answers on the same line. Each input() call reads one line from the
If the program appears to stop after your first answer, read the last line in the terminal. It is probably waiting at the second prompt.
Keep each answer in the right variable
city = input("Which city? ")
country = input("Which country? ")
Clear names let you use the answers in the right places later.
The variables already contain two answers. What will this program print?
first = "blue"
second = "green"
print(f"{second} comes after {first}.")Combine two answers
The starter program asks for a name and an activity. Replace the final print instruction with an
If the answers are Maya and painting, the final line should be:
Maya enjoys painting.
Your code must also work when someone enters different answers. During Run, try answers of your own. During Submit, Python Land supplies two test answers in the same order as the questions.
A useful debugging check is to print each variable temporarily. If the values appear in the wrong places, inspect the order of the input() calls and their variable names.
Task
Replace the final print instruction with an name and activity.
If the two answers are Maya and painting, the final line should be:
Maya enjoys painting.