4 "signature": "sha256:db806d8bbe929161fce8776d2eeac6bad40d1abb93a97d112b974b6a8d50bdd0"
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 "guessed_word = 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: dsf\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 " guessed_word[location] = guessed_letter\n",
227 "language": "python",
232 "output_type": "pyout",
235 "['_', '_', '_', '_', '_', 'e', '_']"
245 "def updated_guessed_word(guessed_word, guessed_letter):\n",
246 " locations = find_all(target, guessed_letter)\n",
247 " for location in locations:\n",
248 " guessed_word[location] = guessed_letter\n",
249 " return guessed_word"
251 "language": "python",
260 "def initialise():\n",
261 " global lives, target, guessed_word, wrong_letters\n",
262 " lives = STARTING_LIVES\n",
263 " target = random.choice(WORDS)\n",
264 " guessed_word = list('_' * len(target))\n",
265 " wrong_letters = []"
267 "language": "python",
277 " global guessed_words, lives, wrong_letters\n",
278 " print('Word:', ' '.join(guessed_word), ' : 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_guessed_word(guessed_word, guess)\n",
284 " wrong_letters += [guess]"
286 "language": "python",
295 "def play_game():\n",
296 " global guessed_word, lives\n",
298 " game_finished = False\n",
300 " while not game_finished:\n",
301 " if '_' not in guessed_word:\n",
302 " print('You won!')\n",
303 " game_finished = True\n",
304 " elif lives <= 0:\n",
305 " print('You lost. The word was', target)\n",
306 " game_finished = True\n",
310 "language": "python",
321 "language": "python",
325 "output_type": "stream",
328 "Word: _ _ _ _ _ _ _ _ _ : Lives = 10 , wrong guesses: \n"
333 "output_type": "stream",
340 "output_type": "stream",
343 "Word: _ _ _ _ _ e _ _ _ : Lives = 10 , wrong guesses: \n"
348 "output_type": "stream",
355 "output_type": "stream",
358 "Word: a _ _ _ _ e _ _ _ : Lives = 10 , wrong guesses: \n"
363 "output_type": "stream",
370 "output_type": "stream",
373 "Word: a _ _ _ _ e t _ _ : Lives = 10 , wrong guesses: \n"
378 "output_type": "stream",
385 "output_type": "stream",
388 "Word: a _ _ o _ e t _ _ : Lives = 10 , wrong guesses: \n"
393 "output_type": "stream",
400 "output_type": "stream",
403 "Word: a _ _ o _ e t _ _ : Lives = 9 , wrong guesses: i\n"
408 "output_type": "stream",
415 "output_type": "stream",
418 "Word: a _ _ o _ e t _ _ : Lives = 8 , wrong guesses: i n\n"
423 "output_type": "stream",
430 "output_type": "stream",
433 "Word: a _ _ o _ e t _ _ : Lives = 7 , wrong guesses: i n s\n"
438 "output_type": "stream",
445 "output_type": "stream",
448 "Word: a _ _ o _ e t _ _ : Lives = 6 , wrong guesses: h i n s\n"
453 "output_type": "stream",
460 "output_type": "stream",
463 "Word: a r _ o r e t _ _ : Lives = 6 , wrong guesses: h i n s\n"
468 "output_type": "stream",
475 "output_type": "stream",
478 "Word: a r _ o r e t _ _ : Lives = 5 , wrong guesses: g h i n s\n"
483 "output_type": "stream",
490 "output_type": "stream",
493 "Word: a r _ o r e t _ _ : Lives = 5 , wrong guesses: g h i n s\n"
498 "output_type": "stream",
505 "output_type": "stream",
508 "Word: a r _ o r e t _ _ : Lives = 4 , wrong guesses: d g h i n s\n"
513 "output_type": "stream",
520 "output_type": "stream",
523 "Word: a r _ o r e t _ _ : Lives = 3 , wrong guesses: d g h i l n s\n"
528 "output_type": "stream",
535 "output_type": "stream",
538 "Word: a r _ o r e t u _ : Lives = 3 , wrong guesses: d g h i l n s\n"
543 "output_type": "stream",
550 "output_type": "stream",
553 "Word: a r b o r e t u _ : Lives = 3 , wrong guesses: d g h i l n s\n"
558 "output_type": "stream",
565 "output_type": "stream",
578 "language": "python",