i was creating a simple guessing game where in the guess is matched to the original string and completes the word.
Encountering 2 errors.
- When wrong guess is made, the else condition is not called and python returns an error.
Traceback (most recent call last):
File “C:/Users/PycharmProjects/Study2.py”, line 12, in
if w.index(x):
ValueError: ‘b’ is not in list - The first letter is not replaced in the guessed word inspite of guessing correctly.
Python Code: (Double-click to select all)
print ( "=====Hangman =====\nGuess the letters to fill the blanks" )
w = [ "o" , "r" , "a" , "n" , "g" , "e" ]
b = [ "_" , "_" , "_" , "_" , "_" , "_" ]
wrong = 0
while b ! = w and wrong < = 6 :
print (b)
x = input ( "Enter your guess: " )
if w.index(x):
i = w.index(x)
b[i] = x
else :
wrong + = 1
if wrong = = 6 :
print ( "Your are out of guesses" )