You are on page 1of 4

1

TICKET BOOKING SYSTEM


(source code- PYTHON)

class Ticket:

def __init__(self, show_time, available_seats, price):

self.show_time = show_time

self.available_seats = available_seats

self.price = price

def book_ticket(self, num_tickets):

if num_tickets <= self.available_seats:

self.available_seats -= num_tickets

cost = num_tickets * self.price

return f"Booked {num_tickets} ticket(s) for {self.show_time}. Total cost:


${cost:.2f}"

else:

return f"Sorry, only {self.available_seats} seat(s) available for


{self.show_time}."

def check_availability(self):
2

return f"For show at {self.show_time}, {self.available_seats} seat(s) are


available."

class MovieTheater:

def __init__(self, name):

self.name = name

self.shows = []

def add_show(self, show_time, available_seats, price):

show = Ticket(show_time, available_seats, price)

self.shows.append(show)

def show_showtimes(self):

showtimes = [show.show_time for show in self.shows]

return showtimes

# Create a movie theater

theater = MovieTheater("Cineplex")

# Add shows

theater.add_show("10:00 AM", 50, 10.00)

theater.add_show("2:00 PM", 60, 12.00)


3

theater.add_show("6:00 PM", 40, 15.00)

while True:

print(f"\nWelcome to {theater.name}!")

print("Available Showtimes:")

showtimes = theater.show_showtimes()

for i, showtime in enumerate(showtimes):

print(f"{i + 1}. {showtime}")

choice = input("Enter the number of your chosen showtime or 'q' to quit: ")

if choice == 'q':

break

try:

choice = int(choice)

if 1 <= choice <= len(showtimes):

selected_show = theater.shows[choice - 1]

print(f"\nYou selected the show at {selected_show.show_time}.")

num_tickets = int(input("How many tickets would you like to book? "))

result = selected_show.book_ticket(num_tickets)

print(result)
4

else:

print("Invalid choice. Please select a valid showtime.")

except ValueError:

print("Invalid input. Please enter a valid choice.")

You might also like