#import the necessary modules import random import turtle #import the lists from categories import categorie_animal from categories import categorie_flower from categories import categorie_vehicle from categories import categorie_clothes from categories import categorie_colour from categories import categorie_emotions from categories import alphabet #Creat a turtle and hide the symbol bob = turtle.Turtle() bob.hideturtle() #Get the length of the word def getLength(): wordLength = [] for i in range(len(randomWord)): wordLength.append('_ ') return wordLength #ask the user which categorie he/she wants to play randomWord = input("What categorie do you want to play? animal, flower, vehicle, clothes, colour or emotions? \n").lower() #Check if the input is correct while randomWord not in ["animal","flower","vehicle","clothes","colour","emotions"]: print ("Invalid input, please try again: \n") randomWord = input("What categorie do you want to play? animal, flower, vehicle, clothes, colour or emotions? \n ").lower() else: print ("The categorie "+randomWord+" is a great choice!") #Get a random word out of the chosen categorie if randomWord == "animal": randomWord = random.choice(categorie_animal) wordLength = getLength() print("" . join(wordLength)) elif randomWord == "flower": randomWord = random.choice(categorie_flower) wordLength = getLength() print("" . join(wordLength)) elif randomWord == "vehicle": randomWord = random.choice(categorie_vehicle) wordLength = getLength() print("" . join(wordLength)) elif randomWord == "clothes": randomWord = random.choice(categorie_clothes) wordLength = getLength() print("" . join(wordLength)) elif randomWord == "colour": randomWord = random.choice(categorie_colour) wordLength = getLength() print("" . join(wordLength)) else: randomWord = random.choice(categorie_emotions) wordLength = getLength() print("" . join(wordLength)) #Set tries to 8 tries = 8 #Save a list with the word length in a variable gussedWord = list(getLength()) #Game while tries > 0: if "".join(gussedWord) == randomWord: print("You are awesome! You gussed the correct word!") #Check if the random Word is fullfilled break print("You get "+ str(tries) + " tries ") #Give the player the info how many tries he/she has gussedLetter = input("Guess a letter: \n").lower() #Ask for a letter #Check if the letter is in random word if gussedLetter in randomWord: #When the gussed letter is in random word print("Correct!") for i in range(len(randomWord)): #Do the for-loop as long as the leght of the random word if list(randomWord)[i] == gussedLetter: #In the loop check if the gussed letter is in the list of the random word gussedWord[i] = gussedLetter #If it is true, put the gussed letter in the list gussed word print("".join(gussedWord)) else: print("That´s a wrong letter!") #Print it ´s wrong tries -= 1 #Reduce the tries #Draw the hangman lines if tries == 7: bob.forward(100) elif tries == 6: bob.backward(50) bob.left(90) bob.forward(200) elif tries == 5: bob.right(90) bob.forward(100) elif tries == 4: bob.right(90) bob.forward (40) elif tries == 3: bob.right(90) bob.circle(15) elif tries == 2: bob.pencolor("white") bob.left(90) bob.forward(30) bob.pencolor("black") bob.forward(40) else: bob.backward(20) bob.right(135) bob.forward(20) bob.backward(20) bob.right(90) bob.forward(20) #Game over else: bob.pencolor("red") bob.left(90) bob.forward(30) bob.right(45) bob.forward(20) bob.backward(20) bob.right(-90) bob.forward(20) print("You ran out of tries! The searched word is: "+randomWord)