๐Ÿ”ค HANGMAN in Python

The same word game โ€” but every string is handled by Python

โ† Back to Fun Time
๐Ÿ Starting Pythonโ€ฆ
Lives
6
Letters tried
0
Wins
0
Losses
0

โŒจ๏ธ Controls

  • Just type a letter โ€” any letter is a guess
  • Or click the alphabet along the bottom of the picture
  • ENTER a new word  โ€ข  ESC pause
  • The A E I O U button tries all five vowels at once.
  • ๐ŸŽฎ Xbox controller? Not this one, sorry โ€” this game is about typing letters, and a controller has no letters on it. Every other game takes a pad.

๐ŸŽฏ How to play

  • A word is hidden. Every letter you find is filled in.
  • A letter that is not in the word costs a life and draws another line.
  • Six wrong guesses and the picture is finished.
  • Guessing the same letter twice is free โ€” it costs nothing.

๐Ÿง  Getting good

  • Start with the vowels: E, A, I, O, U. Almost every word has one.
  • Then the common consonants: R, S, T, N, L.
  • Count the blanks. Short words are much harder than long ones.
  • Look at what you have: _ I O N is not many words.

๐Ÿง‘โ€๐Ÿ’ป This whole game is Python

There is almost no JavaScript on this page. The browser downloaded Pyodide โ€” a complete Python interpreter compiled to WebAssembly โ€” and then ran the .py files in funtime/pylib/. Python does the rules, the maths and the drawing.

File What it does Good functions to try re-writing
pylib/hangman_rules.py The rules: hiding the word, counting mistakes masked_word, is_word_complete, wrong_letters, guess_letter
pylib/hangman_draw.py The drawing โ€” Python calling the canvas draw_gallows, draw_parts, render_game
pylib/hangman_web.py The glue: the keyboard and the alphabet row do_action, on_board_click, start_game

๐Ÿ” Compare the two versions. Open lib/hangman-rules.js and pylib/hangman_rules.py side by side โ€” same ideas, two languages.

๐Ÿ› ๏ธ Build it yourself: Build Hangman in Python walks you through the functions one at a time.

โš ๏ธ If the game never starts: the page has to read its .py files, which a browser will not do for a page opened straight off your disk. Use the live site, or run python3 -m http.server in the project folder.