DAY 27 — 60 DAY PYTHON CHALLENGE
💻 Lottery Game
Python में Lottery Game — लॉटरी खेल
Advertisement
Project kya hai?
Day 27 ka project hai Lottery Game!
Neeche complete code hai — copy karo aur chalao!
Complete Python Code
python — lottery.py
import random
def buy_ticket(numbers_count=6, max_num=49):
return sorted(random.sample(range(1, max_num+1), numbers_count))
def check_matches(ticket, winning):
return len(set(ticket) & set(winning))
print("=== Lottery Game ===")
print("6 numbers choose karo (1-49)
")
budget = 1000
winnings = 0
prizes = {6: 10000000, 5: 50000, 4: 1000, 3: 100, 2: 10}
while True:
print(f"
Budget: Rs{budget} | Total Winnings: Rs{winnings}")
print("1. Ticket khareedo (Rs10)")
print("2. Auto ticket (random)")
print("3. Quick 5 draws")
print("4. Baahar jao")
ch = input("Choice: ")
if ch not in ["1","2","3","4"]: continue
if ch == "4": break
if budget < 10:
print("Budget khatam! Khel khatam.")
break
if ch == "1":
nums = input("6 numbers (1-49, space se): ").split()
try:
ticket = sorted([int(n) for n in nums[:6]])
except:
print("Sahi numbers likho!"); continue
elif ch in ["2","3"]:
draws = 5 if ch == "3" else 1
for d in range(draws):
ticket = buy_ticket()
winning = buy_ticket()
matches = check_matches(ticket, winning)
prize = prizes.get(matches, 0)
budget -= 10
winnings += prize
print(f"
Aapka ticket : {ticket}")
print(f" Winning : {winning}")
print(f" Matches: {matches} | Prize: Rs{prize}")
continue
winning = buy_ticket()
matches = check_matches(ticket, winning)
prize = prizes.get(matches, 0)
budget -= 10
winnings += prize
print(f"
Aapka : {ticket}")
print(f"Winning: {winning}")
print(f"Matches: {matches} | Prize: Rs{prize}")
if matches >= 3: print("Congratulations!")
print(f"
Game Over! Net: Rs{winnings-1000+budget}")
OUTPUT
Budget: Rs1000 Choice: 2 Aapka ticket : [4, 12, 23, 31, 38, 45] Winning : [4, 12, 19, 27, 38, 49] Matches: 3 | Prize: Rs100 Budget: Rs990 | Total Winnings: Rs100
Code kaise kaam karta hai?
random.sample() se unique numbers milte hain. set intersection (&) se matches count hoti hai. Prizes dictionary se reward milta hai.
Advertisement
📋 Project ka Introduction
Lottery Game Python ka Day 27 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: Lottery Game 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:
- 💡 Lottery Game 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: Lottery Game 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.