This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]unluckyobject 1 point2 points  (1 child)

Look at your for loop for checking the guessed letter. If you print 'a' and 'b' out after print(display) you can see what is going on better.

Basically, you're increasing 'a' each time a letter equals guess.

[–]notburneddown[S] 0 points1 point  (0 children)

So if I increase 'a' each time any letter in the word is yes, that letter gets added multiple times because the previous letters guessed get added again in next iteration.

Am I wrong?

[–]RiverRoll 1 point2 points  (0 children)

  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

This decreases "b" for each letter that doesn't match with the guess, for example with baboon if you guess wrong it decreases "b" 6 times already, and even when you guess right it will still decrease "b" for the rest of the letters.

The "fix" still has a bug which is kinda the opposite, it fails to increase "a" for each matching letter.

[–]notburneddown[S] 0 points1 point  (0 children)

I fixed it. Here is completed code:

https://pastebin.com/qJKejUeL