Question: Write a loop that inputs words until the user enters STOP.
Answer:
count = 0
word = input("User Input: ")
while word!="STOP":
count = count+1
print("You entered: "+str(word))
word = input("User Input: ")
print("All done. "+str(count)+" words entered")
Explanation:
This line initializes counter variable count to 0
count = 0
This line prompts user for input
word = input("User Input: ")
The following iteration is executed until user enters STOP
while word!="STOP":
This increments counter variable by 1
count = count+1
This prints the word entered by the user
print("You entered: "+str(word))
This line prompts user for another input
word = input("User Input: ")
This prints the number of input by the user
print("All done. "+str(count)+" words entered")