Guest User

Untitled

a guest
Oct 17th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. import turtle
  2. t = turtle.Turtle()
  3. wn = turtle.Screen()
  4.  
  5. def gallows1():
  6. t.forward(100)
  7.  
  8. def gallows2():
  9. t.backward(50)
  10. t.left(90)
  11. t.forward(200)
  12. t.right(90)
  13.  
  14. def gallows3():
  15. t.forward(100)
  16.  
  17. def gallows4():
  18. t.backward(100)
  19. t.left(90)
  20. t.backward(20)
  21. t.right(45)
  22. t.forward(27)
  23. t.right(45)
  24. t.penup()
  25. t.forward(82)
  26. t.pendown()
  27. t.right(90)
  28.  
  29. def gallows5():
  30. t.forward(40)
  31. t.right(90)
  32.  
  33. def gallows6():
  34. t.circle(20)
  35. t.penup()
  36. t.circle(20,180)
  37. t.pendown()
  38. t.right(90)
  39.  
  40. def gallows7():
  41. t.forward(50)
  42. t.backward(25)
  43. t.right(90)
  44.  
  45. def gallows8():
  46. t.backward(20)
  47. t.penup()
  48. t.forward(20)
  49. t.pendown()
  50. t.forward(20)
  51. t.penup()
  52. t.backward(20)
  53. t.left(90)
  54. t.penup()
  55. t.forward(25)
  56. t.pendown()
  57. t.right(45)
  58.  
  59. def gallows9():
  60. t.forward(30)
  61. t.penup()
  62. t.backward(30)
  63. t.left(90)
  64. t.pendown()
  65.  
  66. def gallows10():
  67. t.forward(30)
  68.  
  69. wrongletters = []
  70. word = input("Enter a word: ")
  71. wordlist = list(word)
  72. hide = " * " * 10
  73. print(hide * 10000)
  74.  
  75. blank = "_" * len(word)
  76. blanklist = list(blank)
  77. for letter in range(len(blanklist)):
  78. if blanklist[letter] != "_":
  79. print(blanklist[letter], end = " ")
  80. else:
  81. print("__", end = " ")
  82. print()
  83.  
  84. while len(wrongletters) < 10:
  85. guess = input("Guess a letter: ")
  86. # l. 87 is checking if the letter guessed by the second user is in the word or not.
  87. if guess in wordlist:
  88. # This checks for every letter in the word if the guess is equal to it, and if
  89. # it is, then the equivalent blank in blanklist is replaced by that letter.
  90. for letter in range(len(word)):
  91. if guess == wordlist[letter]:
  92. blanklist[letter] = wordlist[letter]
  93. # This prints the blanklist. So if the character in blanklist is an underscore,
  94. # then it prints two underscores (for display) followed by two spaces. If the
  95. # character is a letter, however, it prints the letter followed by two spaces.
  96. for letter in range(len(blanklist)):
  97. if blanklist[letter] != "_":
  98. print(blanklist[letter], end = " ")
  99. else:
  100. print("__", end = " ")
  101. print()
  102. else:
  103. wrongletters.append(guess)
  104. print("Letters that are not in the word: " + ", ".join(wrongletters))
  105.  
  106. if len(wrongletters) == 1:
  107. gallows1()
  108. elif len(wrongletters) == 2:
  109. gallows2()
  110. elif len(wrongletters) == 3:
  111. gallows3()
  112. elif len(wrongletters) == 4:
  113. gallows4()
  114. elif len(wrongletters) == 5:
  115. gallows5()
  116. elif len(wrongletters) == 6:
  117. gallows6()
  118. elif len(wrongletters) == 7:
  119. gallows7()
  120. elif len(wrongletters) == 8:
  121. gallows8()
  122. elif len(wrongletters) == 9:
  123. gallows9()
  124. elif len(wrongletters) == 10:
  125. gallows10()
  126. print("You lost.")
  127. print("The word was " + word)
  128. wn.exitonclick()
  129.  
  130. # If there are no more blanks in blanklist, this means that the word has been guessed
  131. # since all the letters have been revealed.
  132. if "_" not in blanklist:
  133. print("Congratulations! The word has been guessed.")
  134. exit()
Add Comment
Please, Sign In to add comment