wordList = []
counter = 0
y = 1
total = 0
wordTotal = 0
while y == 1:
word = input("enter words\n")
continued = input("do you want to continue? y or n ")
if continued == "n":
y = 0
total = total + 1
newWords = []
wordList.append(word)
wordCount = wordList.count(word)
totals = []
if wordCount > 1:
wordTotal = wordTotal - 1
whichWord = newWords.index(word)
totals[whichWord] = totals[whichWord] + 1
if wordCount == 1:
wordTotal = total - wordTotal
newWords.append(word)
print(newWords)
totals.append(1)
print(totals)
if wordTotal == 0:
wordTotal = 1
print("the number of different words is", wordTotal)
This program takes user inputted words, and counts how many repetitions of certain words there are, and how many unqiue words there are. In the second if statement in my code, when I try to index through the array newWords[], and update the value of a repeated word from 1->2, 2->3 etc.., it says ValueError: '...' is not in list. However, when i print the newWords list out in the third if statement, the value is there.
So sorry if I have made an obivous mistake - I am relatively new to python, all help is hugely appreciated :D.