Hangman Game

This is a typical hangman game that is coded using python and uses turtle for the graphical aspects.

# Hangman from random import randint import turtle s = turtle.getscreen() t = turtle.Turtle() t.shapesize(1, 1, 1) t.penup() t.goto(-250, -220) t.pendown() t.goto(-190, -220) t.penup() t.goto(-220, -220) t.pendown() t.goto(-220, 220) t.goto(0, 220) t.goto(0, 170) number = randint(0, 19) words = ["tiger", "television", "cinnamon", "racetrack", "lemonade", "closet", "leopard", "smoothie", "strawberry", "snowman", "pineapple", "counter", "coyote", "sewing", "movement", "paradox", "computer", "eighteen", "musical", "fantastic"] word = words[number] length = len(word) wrong_guesses = [] x = "_" underscore_list = [] for i in range(length): underscore_list.append(x) while len(wrong_guesses) < 6 and "_" in underscore_list: letter_guess = input("Input a letter you think is in the word: ") indexes = [index for index, element in enumerate(word) if element == letter_guess] if letter_guess in word: print("Nice job, that is one of the letters in the word!") for i in range(0, len(indexes)): place = indexes[0] indexes.remove(indexes[0]) underscore_list[place] = letter_guess else: wrong_guesses.append(letter_guess) print("That letter is not in the word, keep trying :)") guesses_left = 6 - len(wrong_guesses) if len(wrong_guesses) == 1: t.penup() t.goto(0, 110) t.pendown() t.circle(30) elif len(wrong_guesses) == 2: t.goto(0, -20) elif len(wrong_guesses) == 3: t.penup() t.goto(0, 90) t.pendown() t.goto(-50, 70) elif len(wrong_guesses) == 4: t.penup() t.goto(0, 90) t.pendown() t.goto(50, 70) elif len(wrong_guesses) == 5: t.penup() t.goto(0, -20) t.pendown() t.goto(-55, -70) print("You have", guesses_left, "wrong guesses left") print("These are the correct letters in the word you have guessed so far: ", underscore_list) print("These are the letters that are not in the word:", wrong_guesses) if "_" not in underscore_list: print("Nice job, you guessed the word and won the game!") elif len(wrong_guesses) == 6: t.penup() t.goto(0, -20) t.pendown() t.goto(55, -70) t.penup() t.goto(-15, 145) t.pendown() t.goto(-10, 140) t.penup() t.goto(-10, 145) t.pendown() t.goto(-15, 140) t.penup() t.goto(15, 145) t.pendown() t.goto(10, 140) t.penup() t.goto(10, 145) t.pendown() t.goto(15, 140) print("You have no more wrong guesses left, this game is lost :(") turtle.done()

This is a user-friendly Hangman game. I was working on it for three weeks.

https://repl.it/@BYLDOG/hangman
print("Starting a game of Hangman.") from random import randint valid1 = 0 x = 0 hg = 0 valid2 = 0 valid27000 = [ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" ] valid30 = [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25" ] valid900 = ["3", "4", "5", "6", "7", "8", "9", "10"] allwords = [ "dog", "cat", "man", "woman", "drums", "cousin", "brother", "epidemic", "pencilcase" ] y = len(allwords) validwords = [] while valid1 == 0: attempts = input("How many incorrect attempts do you want? [1-25] ") if attempts not in valid30: print("Not a valid number from 1 to 25") else: valid1 = 1 attempts = int(attempts) while valid2 == 0: minlen = input("What's the minimum length of the word? [3-10] ") if minlen not in valid900: print("Not a valid number from 3 to 10") else: valid2 = 1 minlen = int(minlen) while x in range(-1, y - 1): x = x + 1 lenx = int(len(allwords[x])) valid3 = max(lenx, minlen) if valid3 == lenx: validwords.append(allwords[x]) wordnm = randint(0, len(validwords) - 1) word = validwords[wordnm] wordlen = len(word) guess = [] wordlist = [] for x in range(0, wordlen): x = x + 1 guess.append("*") wordlist.append(word[x - 1]) while attempts > 0: print(guess) guess1 = input("Enter your guess: ") if guess1 not in valid27000: print( "This is not a valid guess. Try inputting a lowercase English letter" ) else: if guess1 not in wordlist: if attempts != 1: print("This letter is not in the word. Try again") else: print( "This letter is not in the word. You have ran out of attempts." ) attempts = attempts - 1 else: print("This letter is in the word") while hg in range(0, len(wordlist)): if wordlist[hg] == guess1: guess[hg] = guess1 hg = hg + 1 if guess == wordlist: print("You won! Congrats. The word is " + word) while True: aohuni = 1 hg = 0
1