Skip to content

04-09: Hangman Game

Python: Fundamentals

View the live site — ijk37.com

Project 09

Home  |  All Projects  |  Notes  |  Exercises  |  Quiz Hub

Classic word-guessing game with ASCII gallows art. Four word categories (animals, countries, fruits, programming). Tracks win/loss record across multiple rounds.

Topics covered: set · str.isalpha() · random.choice() · all() · while loop · for loop · list display · input validation · functions

Difficulty: ⭐ Beginner


How to Run

python main.py

Sample Session

   ------
   |    |
   |    O
   |   /|\
   |
  ---

  Word : p  _  _  h  o  _
  Wrong guesses (3/6):  a  e  i

  Guess a letter: t
  ✅ 't' is in the word!

Key Concepts Practised

Concept Where used
set guessed_letters, wrong_guesses — fast lookup
all(letter in set for letter in word) Win check
random.choice(list) Word selection
List comprehension-style display build_display()
ASCII art stages HANGMAN_STAGES[len(wrong_guesses)]