DAY 09 — 60 DAY PYTHON CHALLENGE
💻 Word Counter
Python में Word Counter — शब्द, वाक्य, अक्षर गिनें
Advertisement
Complete Code
python — day09.py
def word_counter(): print("📝 Word Counter") print("Text लिखें (empty line = done):") print("-" * 35) lines = [] while True: line = input() if line == "": break lines.append(line) text = " ".join(lines) if not text.strip(): print("❌ कुछ तो लिखें!") return words = text.split() sentences = text.count(".") + text.count("!") + text.count("?") chars_total = len(text) chars_no_sp = len(text.replace(" ", "")) word_freq = {} for w in words: w = w.lower().strip(".,!?") word_freq[w] = word_freq.get(w, 0) + 1 top = sorted(word_freq.items(), key=lambda x: x[1], reverse=True)[:3] print(f"\n📊 Results:") print(f" शब्द: {len(words)}") print(f" वाक्य: {sentences}") print(f" अक्षर (total): {chars_total}") print(f" अक्षर (बिना space): {chars_no_sp}") print(f" Top words: {[w for w,c in top]}") word_counter()
OUTPUT
📊 Results:
शब्द: 25
वाक्य: 3
अक्षर (total): 142
अक्षर (बिना space): 118
Top words: ['python', 'है', 'में']
यह Code कैसे काम करता है?
split() से words list बनती है। Dictionary से word frequency count होती है। sorted() with lambda से top 3 words निकलते हैं।
Advertisement
📋 Project ka Introduction
Word Counter Python ka Day 9 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!
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:
| Concept | Kya karta hai |
|---|---|
Variables | Data store karna |
Functions | Reusable code blocks |
Loops | Repeat karna |
Conditions | Decisions lena |
Input/Output | User se interact karna |
📝 Code kaise kaam karta hai — Step by Step
Neeche code ki poori logic step-by-step samjhayi gayi hai:
- Problem samjho: Word Counter mein kya karna hai
- Required variables aur data structures decide karo
- Logic step-by-step likhó
- Code mein implement karo
- 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:
- 💡 Word Counter 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: Word Counter project kyon banana chahiye?
A: Har project ek naya concept sikhata hai. Practice se hi Python fluent aati hai.
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.
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.
A: Pehle basic version complete karo, phir ek ek feature add karte jao.