DAY 54 — 60 DAY PYTHON CHALLENGE
Color Mixer
Python mein Color Mixer banao — Hindi mein step by step
Advertisement
Project kya hai?
Day 54 ka project hai Color Mixer!
Yeh project banane se aap Python ke important concepts
practice kar payenge. Neeche complete code hai — copy karo aur chalao!
Complete Python Code
python — color.py
def mix_colors(c1, c2):
color_rgb = {
"red": (255, 0, 0),
"green": (0, 255, 0),
"blue": (0, 0, 255),
"white": (255, 255, 255),
"black": (0, 0, 0),
"yellow": (255, 255, 0),
"cyan": (0, 255, 255),
"purple": (128, 0, 128),
"orange": (255, 165, 0),
}
named_mixes = {
("red", "blue"): "Purple",
("blue", "red"): "Purple",
("red", "yellow"): "Orange",
("yellow","red"): "Orange",
("blue", "yellow"): "Green",
("yellow","blue"): "Green",
("red", "white"): "Pink",
("white", "red"): "Pink",
("black", "white"): "Grey",
("white", "black"): "Grey",
}
if c1 not in color_rgb or c2 not in color_rgb:
return None, None, "Invalid color!"
r1, g1, b1 = color_rgb[c1]
r2, g2, b2 = color_rgb[c2]
mixed = ((r1+r2)//2, (g1+g2)//2, (b1+b2)//2)
hex_code = "#{:02X}{:02X}{:02X}".format(*mixed)
result = named_mixes.get((c1, c2), "Custom Color")
return mixed, hex_code, result
available = ["red","green","blue","white","black","yellow","cyan","purple","orange"]
print("=== Color Mixer ===")
print(f"Available: {', '.join(available)}")
while True:
c1 = input("\nColor 1 (q=quit): ").lower()
if c1 == "q": break
c2 = input("Color 2: ").lower()
rgb, hex_c, result = mix_colors(c1, c2)
if rgb:
print(f"\n {c1} + {c2} = {result}")
print(f" RGB : {rgb}")
print(f" HEX : {hex_c}")
else:
print(f" Error: {result}")
OUTPUT
Available: red, green, blue, white... Color 1: red Color 2: blue red + blue = Purple RGB : (127, 0, 127) HEX : #7F007F
Code kaise kaam karta hai?
Tuple se RGB values store hoti hain. Dictionary se named color combinations match hoti hain. format(*mixed) se HEX code banta hai.
Advertisement
📋 Project ka Introduction
Color Mixer Python ka Day 54 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: Color Mixer 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:
- 💡 Color Mixer 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: Color Mixer 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.