DAY 16 — 60 DAY PYTHON CHALLENGE
💻 Prime Number Checker
Python में Prime Number Checker — अभाज्य संख्या
Advertisement
Project kya hai?
Day 16 ka project hai Prime Number!
Neeche complete code hai — copy karo aur chalao!
Complete Python Code
python — prime.py
def is_prime(n):
if n < 2: return False
if n == 2: return True
if n % 2 == 0: return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def primes_upto(limit):
return [n for n in range(2, limit+1) if is_prime(n)]
def prime_factors(n):
factors = []
d = 2
while d * d <= n:
while n % d == 0:
factors.append(d)
n //= d
d += 1
if n > 1:
factors.append(n)
return factors
print("=== Prime Number Checker ===")
while True:
print("
1. Number prime hai ya nahi check karo")
print("2. N tak ke sab prime numbers")
print("3. Prime factors nikalo")
print("4. N consecutive primes dhundho")
print("5. Baahar jao")
ch = input("Choice: ")
if ch == "1":
n = int(input("Number: "))
if is_prime(n):
print(f"{n} PRIME number hai!")
else:
factors = prime_factors(n)
print(f"{n} prime NAHI hai. Factors: {factors}")
elif ch == "2":
limit = int(input("Limit: "))
primes = primes_upto(limit)
print(f"1 to {limit} prime numbers ({len(primes)} total):")
print(f" {primes}")
elif ch == "3":
n = int(input("Number: "))
print(f"{n} ke prime factors: {prime_factors(n)}")
elif ch == "4":
n = int(input("Kitne prime numbers chahiye: "))
primes = []
num = 2
while len(primes) < n:
if is_prime(num):
primes.append(num)
num += 1
print(f"Pehle {n} prime numbers: {primes}")
elif ch == "5":
break
OUTPUT
Number: 17 17 PRIME number hai! Number: 24 24 prime NAHI hai. Factors: [2, 2, 2, 3] 1 to 20 prime numbers (8 total): [2, 3, 5, 7, 11, 13, 17, 19] Pehle 5 prime numbers: [2, 3, 5, 7, 11]
Code kaise kaam karta hai?
Sirf n ke square root tak check karna padta hai - faster! 2 ke multiples skip karte hain. prime_factors() se factorization milta hai.
Advertisement
📋 Project ka Introduction
Prime Number Checker Python ka Day 16 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: Prime Number Checker 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:
- 💡 Prime Number Checker 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: Prime Number Checker 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.