I'm new at python and recently I've been trying to write a code for a hangman game: a part of the MIT OCW course: Introduction to Computer Science and Programming. My code goes as follows:
def write_words (word, al):
neww = (list(word))
newal = (list(al))
x = 0
while (x <= (len(newal))):
z = newal[x]
y = neww.index(z)
except ValueError:
pass
x = x + 1
return (z)
return (y)
when I call the function using write_words ("word", "abcdefghijklmnopqrstuvwxy") I still get the ValueError:'a' is not in list, that is supposed to be corrected with the exception. I 've been trying to figure out the problem, and apparently is a Syntax error. Please, I would be very grateful with any help. My python version is the 3.2.1
returnstatement inside thewhileloop with no conditions. That would return from the function in the first loop. Can you please explain what you are trying to do here?