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

2h 41m 7s logged

Last day of school, and even more coding!
I have a mostly working prototype that can be seen below. There is no hangman sprite yet, but most of the functionality is here.
 
Main.py has been expanded greatly. Now you can choose the game mode and enter characters. It also displays blank, unknown characters as ‘_’ and shows known characters as their letters, printing again after every input.
 
A major bug that remains is that if a word has two identical letters (like ‘a’ in Stardance), only one can be input and uncovered. This is due to code that was meant to prevent people from doing the same wrong answer twice, but it also prevents entering the same right answer twice. This is the culprit code.
 
In the looping code (counter does not go up in the current version, it is mostly a placeholder):

while counter < 10:
    user_input = input("Enter another letter: ")
    if user_input.strip().lower() in already_guessed:        
        print("You already guessed that letter.")        
        continue # Goes to next loop

In the ask_for_letter() function, only a single instance of a letter is uncovered, even if the letter appears more than once.

index = check_letter(word, letter)
if index != -1:
            already_guessed.append(letter)
            message = f"{letter} is in the word at index {index}."
            uncovered_indicies.append(index)
            return index, message

check_letter() only returns a single index, which then only uncovers a single letter in the word. I need to fix this by giving the functions the ability to take and return multiple indexes.
 
The image below shows an example of the current code. The word is ‘cryptic’, but the last ‘c’ cannot be selected.
 
Assuming the word doesn’t have two of the same letter, when the word is guessed the following message is printed:
 
You guessed the word: {secret_word}. Congratulations! 🎉

0
2

Comments 0

No comments yet. Be the first!