4.5 Code Practice
Write a loop that inputs words until the user enters STOP. After each input, the program should number each entry and print in this format:
(This code must be in python, also if a minor explanation can be added to the bottom that would be nice. But also long as u can help I will be fine)

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.  

fnej

Answer:

c = 0

word = input("Enter a word: ")

while word!="STOP":

   c = c+1

   print("#" + str(c) + ": You entered "+str(word))

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

print("All done. "+str(c)+" words entered.")

ACCESS MORE