0% found this document useful (0 votes)
15 views4 pages

BMI Calculator

This Python code defines a Ticket and MovieTheater class to manage ticket bookings. The Ticket class initializes shows with a show time, available seats and price. It has methods to book tickets, returning a confirmation or error, and check availability. The MovieTheater class manages multiple shows by initializing with a name and adding Ticket objects. It displays showtimes and allows booking through a menu-driven interface.

Uploaded by

rathaurha5917
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views4 pages

BMI Calculator

This Python code defines a Ticket and MovieTheater class to manage ticket bookings. The Ticket class initializes shows with a show time, available seats and price. It has methods to book tickets, returning a confirmation or error, and check availability. The MovieTheater class manages multiple shows by initializing with a name and adding Ticket objects. It displays showtimes and allows booking through a menu-driven interface.

Uploaded by

rathaurha5917
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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