DAY 15 — 60 DAY PYTHON CHALLENGE
💻 Fibonacci Series
Python में Fibonacci Series — फिबोनाची श्रृंखला
Advertisement
Project kya hai?
Day 15 ka project hai Fibonacci Series!
Neeche complete code hai — copy karo aur chalao!
Complete Python Code
python — fibonacci.py
def fibonacci_list(n):
if n <= 0: return []
if n == 1: return [0]
fib = [0, 1]
for i in range(2, n):
fib.append(fib[-1] + fib[-2])
return fib
def fibonacci_recursive(n):
if n <= 1: return n
return fibonacci_recursive(n-1) + fibonacci_recursive(n-2)
def is_fibonacci(num):
fib = fibonacci_list(100)
return num in fib
print("=== Fibonacci Series ===")
while True:
print("
1. N terms ki Fibonacci series")
print("2. Nth Fibonacci number")
print("3. Check: kya yeh Fibonacci number hai?")
print("4. Golden Ratio dekho")
print("5. Baahar jao")
ch = input("Choice: ")
if ch == "1":
n = int(input("Kitne terms: "))
fib = fibonacci_list(n)
print(f"Fibonacci ({n} terms):")
print(f" {fib}")
print(f" Sum: {sum(fib)}")
elif ch == "2":
n = int(input("N (1-20): "))
print(f"{n}th Fibonacci: {fibonacci_list(n+1)[-1]}")
elif ch == "3":
num = int(input("Number check karo: "))
if is_fibonacci(num):
print(f"{num} EK Fibonacci number hai!")
else:
print(f"{num} Fibonacci number NAHI hai!")
elif ch == "4":
fib = fibonacci_list(15)
print("
Golden Ratio (consecutive terms ka ratio):")
for i in range(2, min(10, len(fib))):
if fib[i-1] != 0:
ratio = fib[i] / fib[i-1]
print(f" {fib[i]:4} / {fib[i-1]:3} = {ratio:.6f}")
elif ch == "5":
break
OUTPUT
Kitne terms: 10 Fibonacci (10 terms): [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] Sum: 88 10th Fibonacci: 34 Number: 13 13 EK Fibonacci number hai! Golden Ratio: 8 / 5 = 1.600000 13 / 8 = 1.625000 21 / 13 = 1.615385 (1.618... ke paas!)
Code kaise kaam karta hai?
fib[-1] + fib[-2] se pichhle do numbers ka sum. is_fibonacci() mein list mein check karte hain. Golden ratio Fibonacci numbers se aata hai - nature ka secret!
Advertisement
📋 Project ka Introduction
Fibonacci Series Python ka Day 15 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: Fibonacci Series 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:
- 💡 Fibonacci Series 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: Fibonacci Series 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.