🏠 Home 📚 Chapters 💻 Projects ℹ️ About
HomeProjects › Day 25
DAY 25 — 60 DAY PYTHON CHALLENGE

💻 Hangman Game

Python में Hangman Game — शब्द अंदाज़ा खेल

Advertisement

Project kya hai?

Day 25 ka project hai Hangman Game! Neeche complete code hai — copy karo aur chalao!

Complete Python Code

python — hangman.py
import random

words = [
    ("python",    "Programming language"),
    ("variable",  "Data store karne ka naam"),
    ("function",  "Reusable code block"),
    ("loop",      "Repeat karne ka kaam"),
    ("string",    "Text data type"),
    ("integer",   "Pura number"),
    ("boolean",   "True ya False"),
    ("list",      "Ordered collection"),
    ("dictionary","Key-value pairs"),
    ("algorithm", "Problem solving steps"),
]

HANGMAN = [
    "  +---+
  |   |
      |
      |
      |
      |
=========",
    "  +---+
  |   |
  O   |
      |
      |
      |
=========",
    "  +---+
  |   |
  O   |
  |   |
      |
      |
=========",
    "  +---+
  |   |
  O   |
 /|   |
      |
      |
=========",
    "  +---+
  |   |
  O   |
 /|\  |
      |
      |
=========",
    "  +---+
  |   |
  O   |
 /|\  |
 /    |
      |
=========",
    "  +---+
  |   |
  O   |
 /|\  |
 / \  |
      |
=========",
]

word, hint = random.choice(words)
guessed    = set()
wrong      = 0
max_wrong  = 6

print("=== Hangman Game ===")
print(f"Hint: {hint}")
print(f"Word: {len(word)} letters
")

while wrong < max_wrong:
    display = " ".join(c if c in guessed else "_" for c in word)
    print(HANGMAN[wrong])
    print(f"
Word: {display}")
    print(f"Guessed: {sorted(guessed)}")
    print(f"Wrong: {wrong}/{max_wrong}
")
    if "_" not in display:
        print(f"JEEET GAAYE! Word tha: {word}")
        break
    guess = input("Letter guess karo: ").lower()
    if len(guess) != 1 or not guess.isalpha():
        print("Sirf ek letter likho!")
        continue
    if guess in guessed:
        print("Yeh pehle guess kar chuke hain!")
        continue
    guessed.add(guess)
    if guess in word:
        print(f"  '{guess}' sahi hai!")
    else:
        wrong += 1
        print(f"  '{guess}' galat hai!")
else:
    print(HANGMAN[max_wrong])
    print(f"HAAR GAAYE! Word tha: {word}")
OUTPUT
Hint: Data store karne ka naam
Word: 8 letters

  +---+
  |   |
  O   |
 /|\  |
 / \  |
      |
=========
Word: v a r _ _ b _ e
Guessed: ['a', 'b', 'e', 'r', 'v']
Letter: i
  'i' sahi hai!
Word: v a r i a b l e
JEEET GAAYE!

Code kaise kaam karta hai?

Set se guessed letters track hote hain. HANGMAN list mein ASCII art hai. Generator expression se display banta hai - guessed = letter, nahi to _.
Advertisement

📋 Project ka Introduction

Hangman Game Python ka Day 25 ka project hai. Is project mein aap Python ke important concepts practice karenge jo real-world applications mein bahut use hote hain.

Yeh project beginners ke liye design kiya gaya hai lekin kaafi concepts cover karta hai. Step by step samjho, code chalao, aur khud modify karke practice karo.

Is tarah ke projects banane se aapka Python confidence badh jaata hai aur aap asli problems solve karna seekh jaate hain. Chaliye code samjhte hain!

🧠 Is Project mein kya seekhoge?

Yeh project banate waqt aap ye Python concepts use karoge:
ConceptKya karta hai
VariablesData store karna
FunctionsReusable code blocks
LoopsRepeat karna
ConditionsDecisions lena
Input/OutputUser se interact karna

📝 Code kaise kaam karta hai — Step by Step

Neeche code ki poori logic step-by-step samjhayi gayi hai:
  1. Problem samjho: Hangman Game mein kya karna hai
  2. Required variables aur data structures decide karo
  3. Logic step-by-step likhó
  4. Code mein implement karo
  5. Test karo aur bugs fix karo

⚠️ Common Mistakes — Bhool mat jaana!

Beginners yeh galtiyan aksar karte hain — dhyan rakho:
  • ⚠️ Indentation sahi rakho — Python mein spaces matter karti hain
  • ⚠️ Variables ko use se pehle define karo
  • ⚠️ Input ko int()/float() mein convert karo agar number chahiye
  • ⚠️ Edge cases handle karo — kya hoga agar user galat input de?

🏋️ Practice Exercises — Aage badho!

Yeh project complete karne ke baad in exercises se practice karo:
  • 💡 Hangman Game mein naya feature add karo
  • 💡 Code ko functions mein refactor karo
  • 💡 Error handling improve karo
  • 💡 File mein data save karo

❓ Aksar Pooche Jane Wale Sawal (FAQ)

Q: Hangman Game project kyon banana chahiye?

A: Har project ek naya concept sikhata hai. Practice se hi Python fluent aati hai.
Q: Code run nahi ho raha?

A: Indentation check karo, syntax errors dekho, variables define hain ya nahi check karo.
Q: Kaise improve karein?

A: Pehle basic version complete karo, phir ek ek feature add karte jao.
🏠 📋 Projects Day 26 →