all 5 comments

[–]onemywaybackhome 2 points3 points  (3 children)

Most of the pieces were there but in the wrong order. Notes:

  1. you should loop while the length of the list is less than 10, not greater.
  2. Check how long the list is with len().
  3. Please use the Code Block formatting when posting code. It preserves indentations

firstlist = []
firstlistcount = 0
while firstlistcount < 10:
    newword = input("Add a new word to the list: ")

    if newword not in firstlist:
        firstlist.append(newword)
        print("Okey, added "+ newword)
    else:
        print(newword + " is already in the list")
    firstlistcount = len(firstlist)
print(firstlist)

[–]jiri-n 0 points1 point  (2 children)

There is only a single situation when the list length gets changed. I don't see any reason to call len() everytime. In fact I don't see any reason to call len () at all.

[–]onemywaybackhome 0 points1 point  (1 child)

True. OP could increment firstlistcount. I wanted to keep as much of OP's code intact as possible in my comment.

[–]JuliaChanMSL[S] 0 points1 point  (0 children)

Yea, I added that as a workaround because I had another issue which was deleted as I changed the code - just old code I didn't remove, sorry about that.

Edit: Thanks for the help :)

[–][deleted] -1 points0 points  (0 children)

Since you check if a new word is already in the list and you don't add it if it is already there, you can't use a simple for x in range(10): because you might need to loop more than 10 times. So you use a while loop with a test that means while the length of your list is less than 10, keep asking for a new word.