Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import turtle
- t = turtle.Turtle()
- wn = turtle.Screen()
- def gallows1():
- t.forward(100)
- def gallows2():
- t.backward(50)
- t.left(90)
- t.forward(200)
- t.right(90)
- def gallows3():
- t.forward(100)
- def gallows4():
- t.backward(100)
- t.left(90)
- t.backward(20)
- t.right(45)
- t.forward(27)
- t.right(45)
- t.penup()
- t.forward(82)
- t.pendown()
- t.right(90)
- def gallows5():
- t.forward(40)
- t.right(90)
- def gallows6():
- t.circle(20)
- t.penup()
- t.circle(20,180)
- t.pendown()
- t.right(90)
- def gallows7():
- t.forward(50)
- t.backward(25)
- t.right(90)
- def gallows8():
- t.backward(20)
- t.penup()
- t.forward(20)
- t.pendown()
- t.forward(20)
- t.penup()
- t.backward(20)
- t.left(90)
- t.penup()
- t.forward(25)
- t.pendown()
- t.right(45)
- def gallows9():
- t.forward(30)
- t.penup()
- t.backward(30)
- t.left(90)
- t.pendown()
- def gallows10():
- t.forward(30)
- wrongletters = []
- word = input("Enter a word: ")
- wordlist = list(word)
- hide = " * " * 10
- print(hide * 10000)
- blank = "_" * len(word)
- blanklist = list(blank)
- for letter in range(len(blanklist)):
- if blanklist[letter] != "_":
- print(blanklist[letter], end = " ")
- else:
- print("__", end = " ")
- print()
- while len(wrongletters) < 10:
- guess = input("Guess a letter: ")
- # l. 87 is checking if the letter guessed by the second user is in the word or not.
- if guess in wordlist:
- # This checks for every letter in the word if the guess is equal to it, and if
- # it is, then the equivalent blank in blanklist is replaced by that letter.
- for letter in range(len(word)):
- if guess == wordlist[letter]:
- blanklist[letter] = wordlist[letter]
- # This prints the blanklist. So if the character in blanklist is an underscore,
- # then it prints two underscores (for display) followed by two spaces. If the
- # character is a letter, however, it prints the letter followed by two spaces.
- for letter in range(len(blanklist)):
- if blanklist[letter] != "_":
- print(blanklist[letter], end = " ")
- else:
- print("__", end = " ")
- print()
- else:
- wrongletters.append(guess)
- print("Letters that are not in the word: " + ", ".join(wrongletters))
- if len(wrongletters) == 1:
- gallows1()
- elif len(wrongletters) == 2:
- gallows2()
- elif len(wrongletters) == 3:
- gallows3()
- elif len(wrongletters) == 4:
- gallows4()
- elif len(wrongletters) == 5:
- gallows5()
- elif len(wrongletters) == 6:
- gallows6()
- elif len(wrongletters) == 7:
- gallows7()
- elif len(wrongletters) == 8:
- gallows8()
- elif len(wrongletters) == 9:
- gallows9()
- elif len(wrongletters) == 10:
- gallows10()
- print("You lost.")
- print("The word was " + word)
- wn.exitonclick()
- # If there are no more blanks in blanklist, this means that the word has been guessed
- # since all the letters have been revealed.
- if "_" not in blanklist:
- print("Congratulations! The word has been guessed.")
- exit()
Add Comment
Please, Sign In to add comment