In: Computer Science
Write a program that asks the user to enter a bunch of words until they type the word “quit”. Count how many words had 5 letters or more.
Sample program
Enter a word: nothing
Enter a word: stop
Enter a word: word
Enter a word: program
Enter a word: supercalifragilisticexpialidocious
Enter a word: quit
You entered 3 words that were longer than 5 letters.
Explanation:
Here is the code which has the while loop which keeps asking for the words from the user until the user enters 'quit'
At last, it prints the number of words which were having 5 or more than 5 letters.
Code:
count = 0
while(True):
word = input("Enter a word: ")
if(word=='quit'):
break
if len(word)>=5:
count = count + 1
print("You entered", count, "words that were longer than 5 letters.")
Output:
please upvote if you found this helpful!
please comment if you need any help!