Instructions
Write a loop that input words until the user enters STOP. After each input, the program should number each entry and print in this format:
+1: You entered
When stop is entered, the total number of words entered should be printed in this format:
All done. words entered.
Sample Run
Please enter the next word: cat
*1: You entered cat
Please enter the next word: iguana
#2: You entered iguana
Please enter the next word: zebra
#3: You entered zebra
Please enter the next word: dolphin
24: You entered dolphin
Please enter the next word: STOP
All done. 4 words entered.

Respuesta :

i = 0

while True:

user_input = input("Please enter the next word: ")

if user_input == "STOP":

break

i += 1

print("#{}: You entered {}".format(i,user_input))

print("All done. {} words entered.".format(i))

First we set i equal to zero so that we can keep track of how many words we input.

We set while True so that its a continuous loop until a certain condition is met to break out of the loop.

user_input is set equal to whatever word the user enters.

our if statement tells us to break out of the while loop if the user inputs "STOP"

If the user does not enter STOP i is set equal to itself plus 1. This just means we add one to i for every new word entered.

Then we print whichever word is entered.

After the while loop, we print All done and the quantity of words entered.

ACCESS MORE