DAY 17 — 60 DAY PYTHON CHALLENGE
💻 Factorial Calculator
Python में Factorial Calculator — क्रमगुणित
Advertisement
Project kya hai?
Day 17 ka project hai Factorial Calculator!
Neeche complete code hai — copy karo aur chalao!
Complete Python Code
python — factorial.py
def factorial_iterative(n):
if n < 0: return None
result = 1
for i in range(1, n+1):
result *= i
return result
def factorial_recursive(n):
if n < 0: return None
if n == 0 or n == 1: return 1
return n * factorial_recursive(n-1)
import math
print("=== Factorial Calculator ===")
print("n! = 1 x 2 x 3 x ... x n
")
while True:
print("1. Factorial calculate karo")
print("2. Step-by-step dekho")
print("3. Factorial table (1-10)")
print("4. Permutation nPr")
print("5. Combination nCr")
print("6. Baahar jao")
ch = input("Choice: ")
if ch == "1":
n = int(input("N: "))
if n < 0:
print("Negative number ka factorial nahi hota!")
else:
print(f"{n}! = {factorial_iterative(n)}")
elif ch == "2":
n = int(input("N (max 10): "))
steps = " x ".join(str(i) for i in range(1, n+1))
print(f"{n}! = {steps} = {factorial_iterative(n)}")
elif ch == "3":
print("
Factorial Table:")
for i in range(11):
print(f" {i:2}! = {factorial_iterative(i)}")
elif ch == "4":
n = int(input("n: "))
r = int(input("r: "))
nPr = math.factorial(n) // math.factorial(n-r)
print(f"{n}P{r} = {nPr}")
elif ch == "5":
n = int(input("n: "))
r = int(input("r: "))
nCr = math.factorial(n) // (math.factorial(r) * math.factorial(n-r))
print(f"{n}C{r} = {nCr}")
elif ch == "6":
break
OUTPUT
N: 5 5! = 120 Step-by-step: 5! = 1 x 2 x 3 x 4 x 5 = 120 Factorial Table: 0! = 1 1! = 1 2! = 2 3! = 6 4! = 24 5! = 120 10! = 3628800 5P3 = 60 5C3 = 10
Code kaise kaam karta hai?
Loop se ek ek multiply karte hain. Permutation: n! / (n-r)! Combination: n! / (r! x (n-r)!) math.factorial() built-in function hai Python mein!
Advertisement
📋 Project ka Introduction
Factorial Calculator Python ka Day 17 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: Factorial Calculator 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:
- 💡 Factorial Calculator 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: Factorial Calculator 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.