4 "signature": "sha256:a121884b619c7fb25f8da469639386d4238f812c2ed89dc610bede92be57ea00"
27 "WORDS = [w.strip() for w in open('/usr/share/dict/british-english').readlines() \n",
28 " if re.match(r'^[a-z]*$', w.strip())]"
39 "STARTING_LIVES = 10\n",
69 "output_type": "pyout",
89 "output_type": "pyout",
111 "target = random.choice(WORDS)\n",
114 "language": "python",
119 "output_type": "pyout",
132 "discovered = list('_' * len(target))\n",
135 "language": "python",
140 "output_type": "pyout",
143 "['_', '_', '_', '_', '_', '_']"
153 "letter = input('Enter letter: ').strip().lower()[0]\n",
156 "language": "python",
161 "output_type": "stream",
164 "Enter letter: sdfsdfs\n"
169 "output_type": "pyout",
182 "def find_all(string, letter):\n",
185 " location = string.find(letter)\n",
186 " while location > -1:\n",
187 " locations += [location]\n",
188 " starting = location + 1\n",
189 " location = string.find(letter, starting)\n",
192 "language": "python",
201 "find_all('happy', 'q')"
203 "language": "python",
208 "output_type": "pyout",
221 "guessed_letter = 'e'\n",
222 "locations = find_all(target, guessed_letter)\n",
223 "for location in locations:\n",
224 " discovered[location] = guessed_letter\n",
227 "language": "python",
232 "output_type": "pyout",
235 "['_', 'e', '_', '_', '_', '_']"
245 "def updated_discovered_word(discovered, guessed_letter):\n",
246 " locations = find_all(target, guessed_letter)\n",
247 " for location in locations:\n",
248 " discovered[location] = guessed_letter\n",
251 "language": "python",
260 "def initialise():\n",
261 " global lives, target, discovered, wrong_letters\n",
262 " lives = STARTING_LIVES\n",
263 " target = random.choice(WORDS)\n",
264 " discovered = list('_' * len(target))\n",
265 " wrong_letters = []"
267 "language": "python",
277 " global discovered, lives, wrong_letters\n",
278 " print('Word:', ' '.join(discovered), ' : Lives =', lives, ', wrong guesses:', ' '.join(sorted(wrong_letters)))\n",
279 " guess = input('Enter letter: ').strip().lower()[0]\n",
280 " if guess in target:\n",
281 " updated_discovered_word(discovered, guess)\n",
284 " if guess not in wrong_letters:\n",
285 " wrong_letters += [guess]"
287 "language": "python",
296 "def play_game():\n",
297 " global discovered, lives\n",
299 " game_finished = False\n",
301 " while not game_finished:\n",
302 " if '_' not in discovered:\n",
303 " print('You won! The word was', target)\n",
304 " game_finished = True\n",
305 " elif lives <= 0:\n",
306 " print('You lost. The word was', target)\n",
307 " game_finished = True\n",
311 "language": "python",
322 "language": "python",
326 "output_type": "stream",
329 "Word: _ _ _ _ _ _ _ _ _ _ _ _ _ _ : Lives = 10 , wrong guesses: \n"
334 "output_type": "stream",
341 "output_type": "stream",
344 "Word: _ e _ _ _ _ _ _ _ _ _ _ _ _ : Lives = 10 , wrong guesses: \n"
349 "output_type": "stream",
356 "output_type": "stream",
359 "Word: _ e _ _ a _ _ _ _ _ _ _ _ _ : Lives = 10 , wrong guesses: \n"
364 "output_type": "stream",
371 "output_type": "stream",
374 "Word: _ e _ _ a _ _ _ _ _ i _ i _ : Lives = 10 , wrong guesses: \n"
379 "output_type": "stream",
386 "output_type": "stream",
389 "Word: _ e _ _ a _ _ _ o _ i _ i _ : Lives = 10 , wrong guesses: \n"
394 "output_type": "stream",
401 "output_type": "stream",
404 "Word: _ e _ _ a _ _ _ o _ i t i _ : Lives = 10 , wrong guesses: \n"
409 "output_type": "stream",
416 "output_type": "stream",
419 "Word: _ e r _ a _ _ r o _ i t i _ : Lives = 10 , wrong guesses: \n"
424 "output_type": "stream",
431 "output_type": "stream",
434 "Word: _ e r _ a _ _ r o _ i t i _ : Lives = 9 , wrong guesses: n\n"
439 "output_type": "stream",
446 "output_type": "stream",
449 "Word: _ e r _ a _ _ r o _ i t i _ : Lives = 8 , wrong guesses: n s\n"
454 "output_type": "stream",
461 "output_type": "stream",
464 "Word: h e r _ a _ h r o _ i t i _ : Lives = 8 , wrong guesses: n s\n"
469 "output_type": "stream",
476 "output_type": "stream",
479 "Word: h e r _ a _ h r o _ i t i c : Lives = 8 , wrong guesses: n s\n"
484 "output_type": "stream",
491 "output_type": "stream",
494 "Word: h e r _ a _ h r o _ i t i c : Lives = 8 , wrong guesses: n s\n"
499 "output_type": "stream",
506 "output_type": "stream",
509 "Word: h e r m a _ h r o _ i t i c : Lives = 8 , wrong guesses: n s\n"
514 "output_type": "stream",
521 "output_type": "stream",
524 "Word: h e r m a p h r o _ i t i c : Lives = 8 , wrong guesses: n s\n"
529 "output_type": "stream",
536 "output_type": "stream",
539 "You won! The word was hermaphroditic\n"
549 "language": "python",