Reputation: 47
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
Upvotes: 1
Views: 115
Reputation: 34493
You don't have a try
statement there. The format is try-except
. Something like this.
try:
a = 25 / 0
except ZeroDivisionError:
print("Not Possible")
# Output: Not Possible
Upvotes: 4