Ad Code

✨🎆 JOIN MERN, JAVA, PYTHON, AI, DEVOPS, SALESFORCE Courses 🎆✨

Get 100% Placement Oriented Program CLICK to new more info click

PYTHON GAME for Three matching coupon code then First Prize

Python Game – Match the Coupon Codes to Win Exciting Prizes

In this fun and interactive Python game, users try their luck by selecting three coupon codes. The game compares the selected codes with a predefined list of lucky coupons, and based on matches, rewards the user with:

  • 🥇 First Prize – All three selections match
  • 🥈 Second Prize – Any two selections match
  • 🥉 Third Prize – Any one selection matches
  • ❌ Try Again – No matches found

This program is ideal for beginners who want to practice:

  • Set and List concepts
  • Conditional statements
  • Loops
  • User input processing
  • Game logic design

📌 Python Code for the Coupon Matching Game

coupon = {'A1','A2','B1','B2','A3','G7','G8','A0'}

choice1 = input("Enter First coupon code in A1,A2,B1,B2,A3,G7,G8,A0 any of one")
choice2 = input("Enter Second coupon code in A1,A2,B1,B2,A3,G7,G8,A0 any of one")
choice3 = input("Enter Third coupon code in A1,A2,B1,B2,A3,G7,G8,A0 any of one")

i1 = 0
i2 = 0
i3 = 0
lst1 = []

for s in coupon:
    print(s)
    lst1.append(s)

for ls in lst1:
    if choice1 == lst1[0] or choice1 == lst1[1] or choice1 == lst1[2]:
        i1 = 1
    if choice2 == lst1[0] or choice2 == lst1[1] or choice2 == lst1[2]:
        i2 = 2
    if choice3 == lst1[0] or choice3 == lst1[1] or choice3 == lst1[2]:
        i3 = 3

if i1==1 and i2==2 and i3==3:
    print("First Prize")
elif i1==1 and i2==2 or i1==1 and i3==3:
    print("Second Prize")
elif i1==1 or i2==2 or i3==3:
    print("Third prize")
else:
    print("Try again")

🧠 How This Game Works – Step-by-Step

  1. A set of 8 unique coupon codes is created.
  2. The program displays all available coupons.
  3. The user enters three coupon codes of their choice.
  4. The first three coupons in the set become the “lucky” coupons.
  5. The user’s input is compared with these lucky coupons.
  6. Based on the number of matches → Prize is awarded.

📊 Logical Flow (Flowchart Explanation)

START → Show Coupons → Take 3 Inputs → Compare with First 3 Coupons → Count Matches → Display Prize → END

This logic teaches decision-making and game scoring, which is a great foundation for building more advanced Python games.


💡 Sample Output

Available Coupons:
A1
A2
B1
A0
B2
A3
G7
G8

Enter First coupon code: A1
Enter Second coupon code: B1
Enter Third coupon code: A2

Second Prize

⭐ Extra Concept: Why Sets Are Used in This Game?

Sets are used because:

  • They automatically remove duplicates.
  • They provide fast search operations.
  • They keep the game simple and lightweight.

Although sets do not maintain order, converting them to a list (lst1) helps access elements by index.


🚀 Extended Challenge – Improve the Game

To make this game more powerful and fun, try adding enhancements:

  • Random reorder of coupons using import random
  • Scoreboard and replay option
  • Time-based bonus rewards
  • Input validation for invalid coupon codes
  • A GUI version using Tkinter

🎯 Real-World Use-Cases of This Concept

  • Online lucky draw systems
  • Scratch card coupon rewards
  • Gift voucher validation
  • Lottery number comparison logic

❓ Interview Questions Based on This Program

  1. Why is a set used instead of a list?
  2. What is the difference between set and list in Python?
  3. How can the game be improved to handle invalid inputs?
  4. How do you randomize the coupon selection?
  5. What is the time complexity of searching in a set?

🏁 Conclusion

This coupon-matching game is a perfect example of how Python can be used to create fun logic-based programs. It helps beginners strengthen their understanding of:

  • Data structures (set & list)
  • Conditional logic
  • Loops
  • User interaction
  • Game mechanics

You can extend this game into a more advanced mini-project by adding GUI, scoring, animations, or database support.

Post a Comment

1 Comments

  1. #Dice Game
    import threading
    import time
    import random

    class A(threading.Thread):
    def _init__(self):
    super(A,self).__init__()

    def run(self):
    scr1 = 0
    self.c1 = 0
    f1 = True
    while f1:
    self.p1 = input("Press S to start game and E to end the game = ")
    if self.p1 == 's' :
    x1 = random.randint(1,8)
    print("Number is = " + str(x1))
    scr1 = scr1 + x1
    self.c1 =self.c1 +1
    print("Your score is = " + str(scr1))
    if self.p1 =='e':
    print("Game Over")
    break
    if scr1>=20:
    print("PLAYER 1 TRIED = ",str(self.c1)," TIMES")
    break

    class B(threading.Thread):
    def __init__(self):
    super(B,self).__init__()

    def run(self):
    scr2 = 0
    self.c2 = 0
    f2 =True
    while f2:
    self.p2 = input("Press S to start game and E to end the game = ")
    if self.p2 == 's':
    x2 = random.randint(1,8)
    print("Number is = " +str(x2))
    scr2 = scr2 + x2
    self.c2 =self.c2 +1
    print("Your Score is = " +str(scr2))
    if self.p2 == 'e':
    print("Game Over")
    break
    if scr2>=20:
    print("PLAYER 2 TRIED = ",str(self.c2), " TIMES")
    f2 = False

    t1 =A()
    t1.start()
    t1.join()
    t2 =B()
    t2.start()
    t2.join()

    ReplyDelete

POST Answer of Questions and ASK to Doubt