Python Mini Projects
In this page:
Simple Calculator
एक terminal-based calculator user input, string-to-number conversion, और operation चुनने के लिए conditional logic को एक साथ जोड़ता है -- यह एक compact project है जो एक साथ कई fundamentals (input parsing, arithmetic, bad input के लिए error handling) practice कराता है।
उदाहरण: Simple Calculator
def calculate(a, b, op):
if op == "+":
return a + b
elif op == "-":
return a - b
return None # unrecognized operator
print(calculate(5, 3, "+"))
Word Density Counter
एक word-frequency counter input text को अलग-अलग words में split करता है और dictionary (या collections.Counter) से हर word कितनी बार आता है यह गिनता है, यह string processing की एक practical exercise है जो असली documents या user-submitted text analyze करने तक naturally scale हो जाती है।
उदाहरण: Word Density Counter
from collections import Counter
text = "the cat sat on the mat"
counts = Counter(text.split()) # tallies how often each word appears
print(counts)
Custom Password Generator
एक password generator random module का इस्तेमाल करके randomly चुने गए letters, digits और symbols की एक string को, चाहे गई length की एक secure key में जोड़ता है -- यह string building को random selection के साथ practice करने के लिए एक अच्छा project है।
उदाहरण: Custom Password Generator
import random
import string
random.seed(1)
chars = string.ascii_letters + string.digits # pool of characters to choose from
password = "".join(random.choice(chars) for _ in range(8)) # 8 random characters joined together
print(password)
Text Guessing Game
एक number-guessing game एक random target number चुनता है और एक loop के अंदर बार-बार player के guesses की उससे तुलना करता है, सही number मिलने तक higher/lower feedback देता है -- यह loops, conditionals और user interaction की एक सरल पर पूरी exercise है।
उदाहरण: Text Guessing Game
import random
random.seed(1)
target = random.randint(1, 10) # the number the player is trying to guess
guess = 5
if guess < target:
print("Higher")
elif guess > target:
print("Lower")
else:
print("Correct!")
Basic File Organizer
एक file organizer script किसी directory के filenames scan करती है, हर एक की extension inspect करती है, और files को type के हिसाब से subfolders में sort करती है -- यह एक practical automation project है जो os/pathlib modules को असली filesystem data पर basic string handling के साथ जोड़ता है।
उदाहरण: Basic File Organizer
import os
os.makedirs("demo_files/images", exist_ok=True)
with open("demo_files/photo.jpg", "w") as f:
f.write("fake image data")
for filename in os.listdir("demo_files"):
if filename.endswith(".jpg"): # sorts by file extension
print(filename, "-> images/")
Chapter Quiz — Complete all 15 topics to unlock
0/15 topics done
Complete these topics first:
- Python PEP 8 Style Guide
- Python Debugging Techniques
- Python Testing with unittest
- Python Common Mistakes
- Python Interview Questions
- Python map() & filter()
- Python reduce()
- Python zip() & enumerate()
- Python sorted() & key Functions
- Python Comprehensions Advanced
- Python Turtle Graphics
- Python tkinter Introduction
- Python tkinter Widgets
- Python pygame Introduction
- Python Mini Projects