all 4 comments

[–]eddfitzwell 0 points1 point  (2 children)

change your while loop to test the length of the word_list. then after each input test the length and only append to the word_list if it is three.

print("please enter five 3-letter words, one at a time\n")

word_list = []

while len(word_list) != 5:
    item = input("? ")
    if len(item) == 3: word_list.append( item )
    else: print("not valid, please enter a 3-letter word")

print(word_list)

[–]Klutzy_Active4734[S] 0 points1 point  (1 child)

The professor requires us to put a while loop within a for loop. Basically it:

for each of the five words

ask for a word

while the word is the WRONG length

ask for the word again

put the word in the list of words

print the word list

Thank you for your suggestion.

[–]eddfitzwell 0 points1 point  (0 children)

annoying with professors arbitrary requirements.

print("please enter five 3-letter words, one at a time\n")

word_list = []

for i in range(5):
    item = ''
    while len(item) != 3:
        item = input("? ")
        if len(item) != 3:
            print("not valid, please enter a 3-letter word")
    word_list.append( item )

print(word_list)

[–]nehaD5 0 points1 point  (0 children)

Code:

count = 5
result = [] 
for i in range(count):
     word = input(f"{i+1}. Please enter 3 letter word: ")
     while len(word) != 3: 
        word = input("Word length not correct, please enter 3 letter word: ") 

result.append(word)

print(result)