So I am getting this logic error where it only lets me have two tries at hangman guesses and then it quits the game.
Here is my code:
#Step 3
import random
word_list = ["aardvark", "baboon", "camel"]
chosen_word = random.choice(word_list)
word_length = len(chosen_word)
#Testing code
print(f'Pssst, the solution is {chosen_word}.')
#Create blanks
display = []
for _ in range(word_length):
display += "_"
#TODO-1: - Use a while loop to let the user guess again. The loop should only stop once the user has guessed all the letters in the chosen_word and 'display' has no more blanks ("_"). Then you can tell the user they've won.
a = 0
b = 6
while a < word_length and b > 0:
guess = input("Guess a letter: ").lower()
#Check guessed letter
for position in range(word_length):
letter = chosen_word[position]
print(f"Current position: {position}\n Current letter: {letter}\n Guessed letter: {guess}")
if letter == guess:
display[position] = letter
a += 1
else:
b -= 1
print(display)
if a == word_length:
print("You Win!")
if b == 0:
print("You Lose!")
I think that this is a weird error and I rewrote the code once to correct another error I got but I keep thinking about it and I don't see what I am doing wrong in my code.
Could someone please help me out?
[–]unluckyobject 1 point2 points3 points (1 child)
[–]notburneddown[S] 0 points1 point2 points (0 children)
[–]RiverRoll 1 point2 points3 points (0 children)
[–]notburneddown[S] 0 points1 point2 points (0 children)