Q:

Spelling test check not functioning (python)

Very simple error that I've had for quite a while now that I seem to be missing, and it's really bugging me
studentspelling = input ('Spelling: ')
spellingnumber = y6wordlist.index(studentspelling)
if studentspelling == y6wordlist[spellingnumber]:
    print ('Correct. Awarded 2 points.')
    total = total + 2
else:
    print ('Incorrect answer. Awarded no points.')
    total = total

However when I try to input a word during the spelling test that is NOT the word assigned to y6wordlist[spellingnumber] I get this error:
ValueError: 'dgfh' is not in list

now obviously I know that it's not in the list, but none of my code has said that it has to be, or at least I don't think so. I have tried a number of things such as using 'elif' but to no degree of success. Any ideas of what I'm doing wrong? 

A:

The index method will raise a ValueError if the value is not in the list:
>>> a = [1,2,3]
>>> a.index(1)
0
>>> a.index(4)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: 4 is not in list
>>>

You can test whether the word is in the list using in:
if word in mylist:
    i = mylist.index(word)
    # do something
else:
    # do something different

