A quick project to get more comfortable with lists

# Hangman Game
import random
wordlist = ["this","hangman","project","was","fun"]
display = []
choice = random.randint(0,len(wordlist)-1)
word = wordlist[choice]
# print(word) for debugging purposes

for i in word:
    display += "_"
print(display)
def guessing():
    global gg
    guess = str(input("Please guess a letter: ").lower())
    for position in range(len(word)):
        letter = word[position]
        if letter == guess:
            display[position] = letter
            print("good job!")
            gg += 1
            return
    else:
        gg += 1
        print("incorrect")


gg = 0
while "_"  in display:
    guessing()
    print(f"Guesses: {gg}")
    print(display)
while "_" not in display:
    print("Congrats you won!")
    print(f"total guesses!: {gg}")
    input("Press enter to exit")
    exit(420)
Categories: Project

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *