Advertisement
Guest User

CInemaClass

a guest
Apr 29th, 2024
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.55 KB | Source Code | 0 0
  1. #PY-CINEMA
  2. #5 halls in Py-CINEMA:
  3. #COMEDY HALL 10 rows and 20 seats per row
  4. #HORROR HALL 7 rows and 15 seats per row
  5. #ACTION HALL 12 rows and 25 seats per row
  6. #HISTORY HALL 5 rows and 11 seats per row
  7. #DRAMA HALL 8 rows and 12 seats per row
  8.  
  9. class Cinema:
  10.     def __init__(self, rows: int, seats_per_row: int, hall_name: str, movie: str):
  11.         self.rows = rows
  12.         self.seats_per_row = seats_per_row
  13.         self.seats = [[False for __ in range(seats_per_row)] for __ in range(rows)]
  14.         self.hall_name = hall_name
  15.         self.movie = movie
  16.  
  17.  
  18.     def __print_screen(self):
  19.         screen = 'S C R E E N'
  20.         print(f'Layout of "{self.hall_name.upper()}" hall on movie {self.movie.upper()}:')
  21.         print()
  22.         if self.seats_per_row == 6:
  23.             print(screen)
  24.             print()
  25.         elif self.seats_per_row > 6:  # 11 with spaces
  26.             placeholders = (self.seats_per_row + (self.seats_per_row -1)) - len(screen)
  27.             print(("_"*(placeholders//2))+"S C R E E N"+("_"*(placeholders//2)))
  28.         else:
  29.             print('SCREEN')
  30.  
  31.     def print_seats(self):  
  32.         self.__print_screen()
  33.         for row in self.seats:
  34.             for seat in row:
  35.                 if seat:
  36.                     print("X", end=" ")
  37.                 else:
  38.                     print(".", end=" ")
  39.             print()
  40.         print()
  41.  
  42.  
  43.     def book_seat(self, row, seat):
  44.         if 1 <= row <= self.rows and 1 <= seat <= self.seats_per_row:
  45.             if not self.seats[row - 1][seat - 1]:
  46.                 self.seats[row - 1][seat - 1] = True
  47.                 print(f"Seat {seat} in {row} booked successfully.")
  48.             else:
  49.                 print(f"Seat {seat} in {row} is already booked.")
  50.         else:
  51.             print("Invalid row or seat number.")
  52.  
  53.  
  54. comedy_hall = Cinema(10,20, 'comedy', 'American Py')
  55. horror_hall = Cinema(7,15, 'horror', 'Python')
  56. action_hall = Cinema(12,25, 'action', 'the cod3r')
  57. documentary_hall = Cinema(5,11, 'documentary', 'history of code')
  58. drama_hall = Cinema(8,12, 'drama', 'missing semicolon')
  59.  
  60.  
  61. def print_layout_of_all_halls():
  62.     comedy_hall.print_seats()
  63.     horror_hall.print_seats()
  64.     action_hall.print_seats()
  65.     documentary_hall.print_seats()
  66.     drama_hall.print_seats()
  67.    
  68.  
  69. def main():
  70.     print('Welcome in Cinema Py')
  71.     print()
  72.     comedy_hall.print_seats()
  73.     comedy_hall.book_seat(2,5)
  74.     comedy_hall.print_seats()
  75.  
  76.     horror_hall.print_seats()
  77.     horror_hall.book_seat(2,5)
  78.     horror_hall.print_seats()
  79.  
  80.  
  81.  
  82. if __name__ == '__main__':
  83.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement