You are browsing as a guest. Sign up (or log in) to start making projects!

1h 39m 8s logged

Working prototype completed!
 
At this point, all text-related functionality is present. You can enter characters that show up more than once in a word, and it won’t throw errors.
 
I spent the better part of a half hour trying to find out why most times I would enter a letter, it would say that there were none of that letter in the word. This was clearly a bug, as it happened even when entering a letter for a manually chosen word (showing that I wasn’t just an abysmal letter guesser).
 
It turned out that the lack of two characters caused my problem. In my check_letter() function, it creates different letter location lists depending on whether there is one or more instances of that letter in the word. The code is like this.

def check_letter(word: str, letter: str) -> list:
    if isinstance(letter, str) and len(letter) == 1:
        locations = []
        if word.count(letter) == 1:
            locations = [word.find(letter)]
        elif word.count(letter) > 1: # BUG found here! elif was an if statement
            for index, character in enumerate(word):
                if character == letter:
                    locations.append(index)  
        else:
            locations = [-1]      
        return locations # If letter is not in the word, will result in index of -1

The comment that starts with ‘BUG’ shows where the problem originated from. Any word with a single instance of a letter returned [-1] because

if word.count(letter) > 1

would always override an intended single element list.
 
Now, I need to add hangman sprites that will progress as you choose correct or incorrect answers, probably using ASCII characters.

0
1

Comments 0

No comments yet. Be the first!