DAY 20 — 60 DAY PYTHON CHALLENGE
💻 GCD LCM Calculator
Python में GCD और LCM Calculator — महत्तम समापवर्तक
Advertisement
Project kya hai?
Day 20 ka project hai GCD LCM Calculator!
Neeche complete code hai — copy karo aur chalao!
Complete Python Code
python — gcd.py
def gcd(a, b):
while b:
a, b = b, a % b
return a
def lcm(a, b):
return abs(a * b) // gcd(a, b)
def gcd_steps(a, b):
steps = []
while b:
steps.append(f" gcd({a}, {b}): {a} % {b} = {a%b}")
a, b = b, a % b
steps.append(f" GCD = {a}")
return steps, a
print("=== GCD / LCM Calculator ===")
print("GCD = Greatest Common Divisor (sabse bada common factor)")
print("LCM = Least Common Multiple (sabse chhota common multiple)
")
while True:
print("1. Do numbers ka GCD aur LCM")
print("2. Step-by-step Euclidean Algorithm")
print("3. Multiple numbers ka GCD")
print("4. Fraction simplify karo")
print("5. Baahar jao")
ch = input("Choice: ")
if ch == "1":
a = int(input("Pehla number: "))
b = int(input("Doosra number: "))
print(f"
GCD({a}, {b}) = {gcd(a, b)}")
print(f" LCM({a}, {b}) = {lcm(a, b)}")
print(f" Check: {a} x {b} = {a*b} = GCD x LCM = {gcd(a,b)} x {lcm(a,b)} = {gcd(a,b)*lcm(a,b)}")
elif ch == "2":
a = int(input("Pehla number: "))
b = int(input("Doosra number: "))
steps, result = gcd_steps(a, b)
print(f"
Euclidean Algorithm:")
for s in steps:
print(s)
elif ch == "3":
nums = list(map(int, input("Numbers (space se): ").split()))
result = nums[0]
for n in nums[1:]:
result = gcd(result, n)
print(f"GCD of {nums} = {result}")
elif ch == "4":
num = int(input("Numerator (ank): "))
den = int(input("Denominator (haran): "))
g = gcd(num, den)
print(f" {num}/{den} = {num//g}/{den//g} (simplified)")
elif ch == "5":
break
OUTPUT
Pehla number: 48 Doosra number: 18 GCD(48, 18) = 6 LCM(48, 18) = 144 Check: 48 x 18 = 864 = GCD x LCM = 6 x 144 = 864 Fraction simplify: 12/18 = 2/3
Code kaise kaam karta hai?
Euclidean Algorithm: a, b = b, a%b. GCD x LCM = a x b - yeh hamesha sach hai! Fraction simplify mein GCD use hota hai.
Advertisement
📋 Project ka Introduction
GCD LCM Calculator Python ka Day 20 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: GCD LCM 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:
- 💡 GCD LCM 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: GCD LCM 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.