Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #PY-CINEMA
- #5 halls in Py-CINEMA:
- #COMEDY HALL 10 rows and 20 seats per row
- #HORROR HALL 7 rows and 15 seats per row
- #ACTION HALL 12 rows and 25 seats per row
- #HISTORY HALL 5 rows and 11 seats per row
- #DRAMA HALL 8 rows and 12 seats per row
- class Cinema:
- def __init__(self, rows: int, seats_per_row: int, hall_name: str, movie: str):
- self.rows = rows
- self.seats_per_row = seats_per_row
- self.seats = [[False for __ in range(seats_per_row)] for __ in range(rows)]
- self.hall_name = hall_name
- self.movie = movie
- def __print_screen(self):
- screen = 'S C R E E N'
- print(f'Layout of "{self.hall_name.upper()}" hall on movie {self.movie.upper()}:')
- print()
- if self.seats_per_row == 6:
- print(screen)
- print()
- elif self.seats_per_row > 6: # 11 with spaces
- placeholders = (self.seats_per_row + (self.seats_per_row -1)) - len(screen)
- print(("_"*(placeholders//2))+"S C R E E N"+("_"*(placeholders//2)))
- else:
- print('SCREEN')
- def print_seats(self):
- self.__print_screen()
- for row in self.seats:
- for seat in row:
- if seat:
- print("X", end=" ")
- else:
- print(".", end=" ")
- print()
- print()
- def book_seat(self, row, seat):
- if 1 <= row <= self.rows and 1 <= seat <= self.seats_per_row:
- if not self.seats[row - 1][seat - 1]:
- self.seats[row - 1][seat - 1] = True
- print(f"Seat {seat} in {row} booked successfully.")
- else:
- print(f"Seat {seat} in {row} is already booked.")
- else:
- print("Invalid row or seat number.")
- comedy_hall = Cinema(10,20, 'comedy', 'American Py')
- horror_hall = Cinema(7,15, 'horror', 'Python')
- action_hall = Cinema(12,25, 'action', 'the cod3r')
- documentary_hall = Cinema(5,11, 'documentary', 'history of code')
- drama_hall = Cinema(8,12, 'drama', 'missing semicolon')
- def print_layout_of_all_halls():
- comedy_hall.print_seats()
- horror_hall.print_seats()
- action_hall.print_seats()
- documentary_hall.print_seats()
- drama_hall.print_seats()
- def main():
- print('Welcome in Cinema Py')
- print()
- comedy_hall.print_seats()
- comedy_hall.book_seat(2,5)
- comedy_hall.print_seats()
- horror_hall.print_seats()
- horror_hall.book_seat(2,5)
- horror_hall.print_seats()
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement