Question: I have this code for a hangman game Basically what the code does is ask the user to guess a letter from the random word
I have this code for a hangman game
Basically what the code does is ask the user to guess a letter from the random word given and it adds it to a new list
Here it the python code and the error i am getting
#Hangman
import random
stages
wordlistaardvark"baboon","camel"
lives
chosenwordrandom.choicewordlist
printchosenword
placeholder
wordlengthlenchosenword
for position in rangewordlength:
placeholder
printWord to guess:" placeholder
#use a while loop to let the user guess again
gameoverFalse
correctletters
while not gameover:
guessinputGuess a letter: lower
printguess
display
for letter in chosenword:
if letter guess:
displayletter
correctletters.appendguess
elif letter in correctletters:
displayletter
else:
display
printdisplay
if guess not in chosenword:
lives
if lives:
gameoverTrue
printYou lose!"
if not in display:
gameoverTrue
printYou Win"
printstageslives
This is the error
un Task x
camel
Word to guess:
Guess a letter: a
a
a
Guess a letter: m
m
am
Guess a letter: e
e
ame
Guess a letter: c
c
came
Guess a letter: l
l
Traceback most recent call last:
File C:UserstePycharmProjectsPythonProjectFinalvenvPythonScriptsPersonal Days of Code The Complete Python Pro BootcampDayTaskpy line in
printstageslives
IndexError: list index out of range
camel
You Win
Process finished with exit code
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
