Free tutorials & notes in Hindi & English · Clean code examples 🧰 मुफ़्त PDF और फ़ोटो टूल्स →
🟡 Advanced Python  ·  Lesson 31

Python Mini Projects

Mini projects क्यों बनाएँ?

Lessons पढ़ने से syntax आता है; projects से programming आती है। नीचे का हर project इस course के कई topics – functions, loops, dictionaries, files, JSON/CSV और error handling – को एक छोटे tool में जोड़ता है जिसे आप portfolio या practical file में दिखा सकते हैं।

Projectकौन सी skillsLevel
1. Expense trackerloops, functions, dict, JSON file, menusBeginner+
2. Password generatorsecrets, string, any(), setsBeginner
3. Quiz gameJSON, random, enumerate, zip, inputBeginner
4. Attendance reportcsv, Counter, f-string formattingBeginner+

Project 1: data याद रखने वाला Expense tracker

Menu वाला program जो खर्च जोड़ता है, उन्हें expenses.json में रखता है और text bar chart के साथ category-wise report छापता है। Program बंद करने के बाद भी data बचा रहता है।

Python – expense_tracker.py
"""Expense tracker – saves to expenses.json between runs."""
import json
from datetime import date
from pathlib import Path

FILE = Path("expenses.json")
CATEGORIES = ["food", "travel", "books", "bills", "other"]


def load():
    if FILE.exists():
        return json.loads(FILE.read_text(encoding="utf-8"))
    return []


def save(expenses):
    FILE.write_text(json.dumps(expenses, indent=2), encoding="utf-8")


def add(expenses):
    amount = float(input("Amount (₹): "))
    category = input(f"Category {CATEGORIES}: ").strip().lower()
    if category not in CATEGORIES:
        category = "other"
    note = input("Note: ").strip()
    expenses.append({"date": date(2026, 10, 25).isoformat(), "amount": amount, "category": category, "note": note})
    save(expenses)
    print("✅ saved")


def report(expenses):
    total = sum(e["amount"] for e in expenses)
    print(f"Total spent: ₹{total:,.0f}")
    by_cat = {}
    for e in expenses:
        by_cat[e["category"]] = by_cat.get(e["category"], 0) + e["amount"]
    for cat, amt in sorted(by_cat.items(), key=lambda x: -x[1]):
        bar = "█" * int(amt / total * 20)
        print(f"  {cat:<7} ₹{amt:>7,.0f} {bar}")


def main():
    expenses = load()
    while True:
        choice = input("\n1) Add  2) Report  3) Quit → ")
        if choice == "1":
            add(expenses)
        elif choice == "2":
            report(expenses)
        elif choice == "3":
            print("Bye!")
            break
        else:
            print("Please type 1, 2 or 3")


if __name__ == "__main__":
    main()
1) Add 2) Report 3) Quit → 1 Amount (₹): 450 Category ['food', 'travel', 'books', 'bills', 'other']: food Note: Pizza with friends ✅ saved 1) Add 2) Report 3) Quit → 1 Amount (₹): 1200 Category ['food', 'travel', 'books', 'bills', 'other']: books Note: NCERT guides ✅ saved 1) Add 2) Report 3) Quit → 1 Amount (₹): 180 Category ['food', 'travel', 'books', 'bills', 'other']: travel Note: Auto ✅ saved 1) Add 2) Report 3) Quit → 2 Total spent: ₹1,830 books ₹ 1,200 █████████████ food ₹ 450 ████ travel ₹ 180 █ 1) Add 2) Report 3) Quit → 5 Please type 1, 2 or 3 1) Add 2) Report 3) Quit → 3 Bye!
  • Path.read_text/write_text से file code छोटा रहता है।
  • ग़लत category पर crash की जगह “other”।
  • Report categories को रक़म से sort करके "█" * n से bars बनाती है।
  • सुधारें: खर्च delete करना, महीने का filter, CSV export।
📝 Date के बारे में

Output एक जैसा रहे इसलिए demo में तय date है। अपनी copy में date(2026, 10, 25) को date.today() से बदलें।

Project 2: मज़बूत password generator और checker

Python – password_tool.py
"""Strong password generator + strength checker."""
import secrets
import string


def generate(length=12):
    if length < 8:
        raise ValueError("use at least 8 characters")
    pools = [string.ascii_lowercase, string.ascii_uppercase, string.digits, "!@#$%&*?"]
    chars = [secrets.choice(pool) for pool in pools]              # one from each pool
    everything = "".join(pools)
    chars += [secrets.choice(everything) for _ in range(length - len(chars))]
    secrets.SystemRandom().shuffle(chars)
    return "".join(chars)


def strength(pw):
    checks = {
        "8+ characters": len(pw) >= 8,
        "lowercase": any(c.islower() for c in pw),
        "uppercase": any(c.isupper() for c in pw),
        "digit": any(c.isdigit() for c in pw),
        "symbol": any(not c.isalnum() for c in pw),
        "not common": pw.lower() not in {"password", "12345678", "qwerty123", "india@123"},
    }
    score = sum(checks.values())
    missing = [name for name, ok in checks.items() if not ok]
    label = "strong" if score == 6 else "medium" if score >= 4 else "weak"
    return label, missing


new = generate(14)
print("generated length:", len(new), "| strength:", strength(new)[0])
for pw in ["india@123", "Gagan2026", "Riya#Delhi2026"]:
    label, missing = strength(pw)
    print(f"{pw:<15} {label:<7} missing: {', '.join(missing) or '-'}")
generated length: 14 | strength: strong india@123 medium missing: uppercase, not common Gagan2026 medium missing: symbol Riya#Delhi2026 strong missing: -
  • Passwords के लिए random नहीं, secrets – यह security के लिए बना है।
  • हर pool से एक character लेने से हर नियम पूरा होना पक्का है।
  • Checker बताता है कि password कमज़ोर क्यों है, जो सिर्फ़ score से ज़्यादा उपयोगी है।

Project 3: JSON file से Quiz game

JSON – questions.json
[
  {"q": "Which keyword defines a function in Python?", "options": ["func", "def", "function", "define"], "answer": 1},
  {"q": "What does len([3, 5, 7]) return?", "options": ["2", "3", "7", "15"], "answer": 1},
  {"q": "Which type is immutable?", "options": ["list", "dict", "set", "tuple"], "answer": 3}
]
Python – quiz.py
"""Quiz game – questions come from a JSON file, score is saved."""
import json
import random

random.seed(7)                     # remove this line for a different order every time

with open("questions.json", encoding="utf-8") as f:
    questions = json.load(f)

random.shuffle(questions)
score = 0
for i, q in enumerate(questions, start=1):
    print(f"\nQ{i}. {q['q']}")
    for letter, option in zip("abcd", q["options"]):
        print(f"   {letter}) {option}")
    answer = input("Your answer: ").strip().lower()
    correct = "abcd"[q["answer"]]
    if answer == correct:
        score += 1
        print("✔ Correct")
    else:
        print(f"✘ Wrong – correct answer is {correct}) {q['options'][q['answer']]}")

print(f"\nScore: {score}/{len(questions)} ({score / len(questions):.0%})")
Q1. Which type is immutable? a) list b) dict c) set d) tuple Your answer: d ✔ Correct Q2. Which keyword defines a function in Python? a) func b) def c) function d) define Your answer: c ✘ Wrong – correct answer is b) def Q3. What does len([3, 5, 7]) return? a) 2 b) 3 c) 7 d) 15 Your answer: b ✔ Correct Score: 2/3 (67%)

सवाल JSON file में हैं, इसलिए teacher code छुए बिना 50 नए सवाल जोड़ सकता है। Ideas: हर सवाल का timer, categories, high scores file में save।

Project 4: CSV register से Attendance report

CSV – attendance.csv
name,Mon,Tue,Wed,Thu,Fri,Sat
Asha,P,P,P,P,P,P
Ravi,P,A,P,A,A,P
Neha,P,P,A,P,P,P
Kabir,A,P,P,P,A,A
Python – attendance_report.py
"""Attendance summary from a CSV register."""
import csv
from collections import Counter

with open("attendance.csv", newline="", encoding="utf-8") as f:
    rows = list(csv.DictReader(f))

days = [d for d in rows[0] if d != "name"]
print(f"{'Name':<8} {'Present':>7} {'%':>6}  Status")
present_per_day = Counter()
for r in rows:
    present = sum(r[d] == "P" for d in days)
    for d in days:
        present_per_day[d] += r[d] == "P"
    pct = present / len(days) * 100
    status = "OK" if pct >= 75 else "⚠ below 75%"
    print(f"{r['name']:<8} {present:>7} {pct:>5.0f}%  {status}")

low_day, count = min(present_per_day.items(), key=lambda x: x[1])
print(f"\nLowest attendance: {low_day} ({count}/{len(rows)} students)")
Name Present % Status Asha 6 100% OK Ravi 3 50% ⚠ below 75% Neha 5 83% OK Kabir 3 50% ⚠ below 75% Lowest attendance: Fri (2/4 students)

Teachers register को Google Sheets से CSV में export करके एक सेकंड में यह report पा सकते हैं। आगे बढ़ाएँ: 75% से कम वाले students के parents को email, या matplotlib से attendance chart।

और project ideas (पहले कौन सा lesson पढ़ें)

Projectपहले पढ़ें
Free API से Weather reportAPIs और requests
Price list scraper से CSVWeb scraping
SQLite के साथ Library managementSQLite के साथ SQL
Student marks dashboardStudent performance project
Tests के साथ Bill generatorTesting और debugging

Project कैसे present करें

  1. हर project को अपने folder में README.md के साथ रखें: क्या करता है, कैसे चलाएँ, sample output।
  2. Packages हों तो requirements.txt जोड़ें।
  3. GitHub पर upload करके link resume में जोड़ें।
  4. एक design फ़ैसला समझाने को तैयार रहें (जैसे JSON क्यों, secrets क्यों)।

अक्सर पूछे जाने वाले प्रश्न (FAQ)

क्या ये projects Class 11/12 practical file में इस्तेमाल कर सकते हैं?
हाँ। इन्हें ख़ुद type करें, चलाएँ, हर line समझें और अपना एक सुधार जोड़ें – teachers copy किए लंबे program से ज़्यादा उस छोटे बदलाव को महत्व देते हैं जिसे आप समझा सकें।
क्या कुछ install करना होगा?
नहीं। चारों projects सिर्फ़ Python standard library (json, csv, secrets, random, pathlib, collections) इस्तेमाल करते हैं।
← Back to Python Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

💻 लाइव कोड एडिटर

इस पेज के प्रोग्राम यहीं तैयार हैं — चलाएँ, बदलें और सीखें। कुछ भी इंस्टॉल किए बिना।
OneCompiler द्वारा संचालित। कोड एडिटर में अपने आप आ जाता है — Run दबाकर आउटपुट देखें। अगर एडिटर न खुले तो नए टैब में खोलें.
अगला topicLinear Algebra Basics आपकी प्रगति: 31 / 66 (47%) · Lesson 32 / 66 आगे बढ़ें →

यह lesson कैसा लगा?

आपकी राय से हम content और बेहतर बनाते हैं।

अपना review और सुझाव लिखें (वैकल्पिक)

Review approve होने के बाद आपका नाम और शहर इसके साथ public दिख सकते हैं। Email या phone न लिखें।

▶ CodingEasily on YouTube

Video से सीखें – आसान Hindi में

चुनी हुई video: RDBMS भाग 3 – Class XI Commerce IT

▶ Channel subscribe करें