Poli_Monoteista

Wisielec, propozycja z kursu

Jan 10th, 2022
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.60 KB | None | 0 0
  1. hangman_art.py
  2. stages = ['''
  3.  +---+
  4.  |   |
  5.  O   |
  6. /|\ |
  7. / \ |
  8.      |
  9. =========
  10. ''', '''
  11.  +---+
  12.  |   |
  13.  O   |
  14. /|\ |
  15. /    |
  16.      |
  17. =========
  18. ''', '''
  19.  +---+
  20.  |   |
  21.  O   |
  22. /|\ |
  23.      |
  24.      |
  25. =========
  26. ''', '''
  27.  +---+
  28.  |   |
  29.  O   |
  30. /|   |
  31.      |
  32.      |
  33. =========''', '''
  34.  +---+
  35.  |   |
  36.  O   |
  37.  |   |
  38.      |
  39.      |
  40. =========
  41. ''', '''
  42.  +---+
  43.  |   |
  44.  O   |
  45.      |
  46.      |
  47.      |
  48. =========
  49. ''', '''
  50.  +---+
  51.  |   |
  52.      |
  53.      |
  54.      |
  55.      |
  56. =========
  57. ''']
  58.  
  59. logo = '''
  60. _                                            
  61. | |                                            
  62. | |__   __ _ _ __   __ _ _ __ ___   __ _ _ __  
  63. | '_ \ / _` | '_ \ / _` | '_ ` _ \ / _` | '_ \
  64. | | | | (_| | | | | (_| | | | | | | (_| | | | |
  65. |_| |_|\__,_|_| |_|\__, |_| |_| |_|\__,_|_| |_|
  66.                    __/ |                      
  67.                   |___/    '''
  68.  
  69.                                                                    
  70.                                                                    
  71. hangman_words.py
  72. word_list = [
  73. 'abruptly',
  74. 'absurd',
  75. 'abyss',
  76. 'affix',
  77. 'askew',
  78. 'avenue',
  79. 'awkward',
  80. 'axiom',
  81. 'azure',
  82. 'bagpipes',
  83. 'bandwagon',
  84. 'banjo',
  85. 'bayou',
  86. 'beekeeper',
  87. 'bikini',
  88. 'blitz',
  89. 'blizzard',
  90. 'boggle',
  91. 'bookworm',
  92. 'boxcar',
  93. 'boxful',
  94. 'buckaroo',
  95. 'buffalo',
  96. 'buffoon',
  97. 'buxom',
  98. 'buzzard',
  99. 'buzzing',
  100. 'buzzwords',
  101. 'caliph',
  102. 'cobweb',
  103. 'cockiness',
  104. 'croquet',
  105. 'crypt',
  106. 'curacao',
  107. 'cycle',
  108. 'daiquiri',
  109. 'dirndl',
  110. 'disavow',
  111. 'dizzying',
  112. 'duplex',
  113. 'dwarves',
  114. 'embezzle',
  115. 'equip',
  116. 'espionage',
  117. 'euouae',
  118. 'exodus',
  119. 'faking',
  120. 'fishhook',
  121. 'fixable',
  122. 'fjord',
  123. 'flapjack',
  124. 'flopping',
  125. 'fluffiness',
  126. 'flyby',
  127. 'foxglove',
  128. 'frazzled',
  129. 'frizzled',
  130. 'fuchsia',
  131. 'funny',
  132. 'gabby',
  133. 'galaxy',
  134. 'galvanize',
  135. 'gazebo',
  136. 'giaour',
  137. 'gizmo',
  138. 'glowworm',
  139. 'glyph',
  140. 'gnarly',
  141. 'gnostic',
  142. 'gossip',
  143. 'grogginess',
  144. 'haiku',
  145. 'haphazard',
  146. 'hyphen',
  147. 'iatrogenic',
  148. 'icebox',
  149. 'injury',
  150. 'ivory',
  151. 'ivy',
  152. 'jackpot',
  153. 'jaundice',
  154. 'jawbreaker',
  155. 'jaywalk',
  156. 'jazziest',
  157. 'jazzy',
  158. 'jelly',
  159. 'jigsaw',
  160. 'jinx',
  161. 'jiujitsu',
  162. 'jockey',
  163. 'jogging',
  164. 'joking',
  165. 'jovial',
  166. 'joyful',
  167. 'juicy',
  168. 'jukebox',
  169. 'jumbo',
  170. 'kayak',
  171. 'kazoo',
  172. 'keyhole',
  173. 'khaki',
  174. 'kilobyte',
  175. 'kiosk',
  176. 'kitsch',
  177. 'kiwifruit',
  178. 'klutz',
  179. 'knapsack',
  180. 'larynx',
  181. 'lengths',
  182. 'lucky',
  183. 'luxury',
  184. 'lymph',
  185. 'marquis',
  186. 'matrix',
  187. 'megahertz',
  188. 'microwave',
  189. 'mnemonic',
  190. 'mystify',
  191. 'naphtha',
  192. 'nightclub',
  193. 'nowadays',
  194. 'numbskull',
  195. 'nymph',
  196. 'onyx',
  197. 'ovary',
  198. 'oxidize',
  199. 'oxygen',
  200. 'pajama',
  201. 'peekaboo',
  202. 'phlegm',
  203. 'pixel',
  204. 'pizazz',
  205. 'pneumonia',
  206. 'polka',
  207. 'pshaw',
  208. 'psyche',
  209. 'puppy',
  210. 'puzzling',
  211. 'quartz',
  212. 'queue',
  213. 'quips',
  214. 'quixotic',
  215. 'quiz',
  216. 'quizzes',
  217. 'quorum',
  218. 'razzmatazz',
  219. 'rhubarb',
  220. 'rhythm',
  221. 'rickshaw',
  222. 'schnapps',
  223. 'scratch',
  224. 'shiv',
  225. 'snazzy',
  226. 'sphinx',
  227. 'spritz',
  228. 'squawk',
  229. 'staff',
  230. 'strength',
  231. 'strengths',
  232. 'stretch',
  233. 'stronghold',
  234. 'stymied',
  235. 'subway',
  236. 'swivel',
  237. 'syndrome',
  238. 'thriftless',
  239. 'thumbscrew',
  240. 'topaz',
  241. 'transcript',
  242. 'transgress',
  243. 'transplant',
  244. 'triphthong',
  245. 'twelfth',
  246. 'twelfths',
  247. 'unknown',
  248. 'unworthy',
  249. 'unzip',
  250. 'uptown',
  251. 'vaporize',
  252. 'vixen',
  253. 'vodka',
  254. 'voodoo',
  255. 'vortex',
  256. 'voyeurism',
  257. 'walkway',
  258. 'waltz',
  259. 'wave',
  260. 'wavy',
  261. 'waxy',
  262. 'wellspring',
  263. 'wheezy',
  264. 'whiskey',
  265. 'whizzing',
  266. 'whomever',
  267. 'wimpy',
  268. 'witchcraft',
  269. 'wizard',
  270. 'woozy',
  271. 'wristwatch',
  272. 'wyvern',
  273. 'xylophone',
  274. 'yachtsman',
  275. 'yippee',
  276. 'yoked',
  277. 'youthful',
  278. 'yummy',
  279. 'zephyr',
  280. 'zigzag',
  281. 'zigzagging',
  282. 'zilch',
  283. 'zipper',
  284. 'zodiac',
  285. 'zombie',
  286. ]
  287.  
  288. main.py
  289.  
  290. #Step 5
  291.  
  292. import random
  293.  
  294. #TODO-1: - Update the word list to use the 'word_list' from hangman_words.py
  295. #Delete this line: word_list = ["ardvark", "baboon", "camel"]
  296. from hangman_words import word_list
  297.  
  298. chosen_word = random.choice(word_list)
  299. word_length = len(chosen_word)
  300.  
  301. end_of_game = False
  302. lives = 6
  303.  
  304. #TODO-3: - Import the logo from hangman_art.py and print it at the start of the game.
  305. from hangman_art import logo
  306. print(logo)
  307.  
  308. #Testing code
  309. print(f'Pssst, the solution is {chosen_word}.')
  310.  
  311. #Create blanks
  312. display = []
  313. for _ in range(word_length):
  314.     display += "_"
  315.  
  316. while not end_of_game:
  317.     guess = input("Guess a letter: ").lower()
  318.  
  319.     #TODO-4: - If the user has entered a letter they've already guessed, print the letter and let them know.
  320.     if guess in display:
  321.         print(f"You've already guessed {guess}")
  322.  
  323.     #Check guessed letter
  324.     for position in range(word_length):
  325.         letter = chosen_word[position]
  326.         #print(f"Current position: {position}\n Current letter: {letter}\n Guessed letter: {guess}")
  327.         if letter == guess:
  328.             display[position] = letter
  329.  
  330.     #Check if user is wrong.
  331.     if guess not in chosen_word:
  332.         #TODO-5: - If the letter is not in the chosen_word, print out the letter and let them know it's not in the word.
  333.         print(f"You guessed {guess}, that's not in the word. You lose a life.")
  334.        
  335.         lives -= 1
  336.         if lives == 0:
  337.             end_of_game = True
  338.             print("You lose.")
  339.  
  340.     #Join all the elements in the list and turn it into a String.
  341.     print(f"{' '.join(display)}")
  342.  
  343.     #Check if user has got all letters.
  344.     if "_" not in display:
  345.         end_of_game = True
  346.         print("You win.")
  347.  
  348.     #TODO-2: - Import the stages from hangman_art.py and make this error go away.
  349.     from hangman_art import stages
  350.     print(stages[lives])
Add Comment
Please, Sign In to add comment