Apr-20-2020, 05:56 PM
@deanhystad thanks for code. I m still understanding the functions and parameters in it. its pretty awesome. i was having trouble using strings.
as for my code, i removed index function from the if condition and rewrote the code. its working now. Both errors are addressed.
as for my code, i removed index function from the if condition and rewrote the code. its working now. Both errors are addressed.
print("=====Hangman =====\nGuess the letters to fill the blanks") w = ["f", "l", "a", "m", "e", "s"] b = ["_", "_", "_", "_", "_", "_"] wrong = 0 while b != w and wrong <6: print(b) x = input("Enter your guess: ") if x in w: i = w.index(x) b[i] = x else: wrong += 1 print("Wrong guesses : " + str(wrong)) if wrong == 6: print("Your are out of guesses") if b == w: print(b) print("\n You Win !!")
Output:=====Hangman =====
Guess the letters to fill the blanks
['_', '_', '_', '_', '_', '_']
Enter your guess: a
['_', '_', 'a', '_', '_', '_']
Enter your guess: s
['_', '_', 'a', '_', '_', 's']
Enter your guess: q
Wrong guesses : 1
['_', '_', 'a', '_', '_', 's']
Enter your guess: w
Wrong guesses : 2
['_', '_', 'a', '_', '_', 's']
Enter your guess: e
['_', '_', 'a', '_', 'e', 's']
Enter your guess: f
['f', '_', 'a', '_', 'e', 's']
Enter your guess: l
['f', 'l', 'a', '_', 'e', 's']
Enter your guess: z
Wrong guesses : 3
['f', 'l', 'a', '_', 'e', 's']
Enter your guess: x
Wrong guesses : 4
['f', 'l', 'a', '_', 'e', 's']
Enter your guess: v
Wrong guesses : 5
['f', 'l', 'a', '_', 'e', 's']
Enter your guess: b
Wrong guesses : 6
Your are out of guesses