You are on page 1of 2

class Customer:

def __init__(self, name, phone):


self.name = name
self.phone = phone

class Game:
def __init__(self, game_id, game_name, available_seats):
self.game_id = game_id
self.game_name = game_name
self.available_seats = available_seats

def book_ticket(self, customer, no_of_seats):


if self.available_seats >= no_of_seats:
self.available_seats -= no_of_seats
print(f"Successfully booked {no_of_seats} tickets for
{customer.name}.")
else:
print("Sorry, we don't have enough available seats.")

class TicketBookingSystem:
def __init__(self):
self.customers = {}
self.games = {}

def add_customer(self, customer):


self.customers[customer.phone] = customer

def add_game(self, game):


self.games[game.game_id] = game

def book_ticket(self, phone, game_id, no_of_seats):


if phone in self.customers:
if game_id in self.games:
if self.games[game_id].available_seats >= no_of_seats:
self.games[game_id].book_ticket(self.customers[phone],
no_of_seats)
else:
print("Sorry, we don't have enough available seats.")
else:
print("This game is not available.")
else:
print("This customer does not exist.")

booking_system = TicketBookingSystem()
customer1 = Customer("Abbas", "4684690032")
customer2 = Customer("mohammed", "9876543210")
customer3=Customer("ezzaldin","077418911")
booking_system.add_customer(customer1)
booking_system.add_customer(customer2)
booking_system.add_customer(customer3)

game1 = Game("1", "Game 1", 50)


game2 = Game("2", "Game 2", 60)

game1.game_name = "Game 1"


game2.game_name = "Game 2"
booking_system.add_game(game1)
booking_system.add_game(game2)

game3 = Game("3", "Game 3", 50)


game4 = Game("4", "Game 4", 40)
booking_system.add_game(game3)
booking_system.add_game(game4)

booking_system.book_ticket("4684690032", "1", 70)


booking_system.book_ticket("9876543210", "2", 20)
booking_system.book_ticket("077418911", "3", 30)
booking_system.book_ticket("65658", "4", 10)

You might also like