Summiya14Fis14Samaa

Untitled

Dec 18th, 2021
1,117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.07 KB | None | 0 0
  1. class Seat():
  2.     def __init__(self):
  3.         self.letter = "A"
  4.         self.available = True
  5.         self.studID = None
  6.     def setLetter(self, letter):
  7.         self.letter = letter
  8.         pass
  9.    
  10.     def checkAvailable(self):
  11.         return self.available
  12.         pass
  13.  
  14.     def enterStudent(self, studID):
  15.         self.studID = studID
  16.         self.available = False
  17.         pass
  18.  
  19.     def exitStudent(self):
  20.         self.studID = None
  21.         self.available = True
  22.         pass
  23.  
  24.  
  25.     def showinfo(self):
  26.         print(f'\nseat: {self.letter}')
  27.         print(f'availability: {self.checkAvailable()}')
  28.         if self.available:
  29.             print(f'Student residing: {self.studID}')
  30.  
  31.  
  32.  
  33.  
  34. class Room():
  35.     def __init__(self):
  36.         self.roomNo = "###"
  37.         self.seats = list()
  38.         seatA = Seat()
  39.         seatA.setLetter('A')
  40.         self.seats.append(seatA)
  41.        
  42.         seatB = Seat()
  43.         seatB.setLetter('B')
  44.         self.seats.append(seatB)
  45.        
  46.  
  47.     def setNumber(self, number):
  48.         self.roomNo = number
  49.         if self.roomNo in (501, 502, 504):
  50.             seatC = Seat()
  51.             seatC.setLetter('C')
  52.             self.seats.append(seatC)
  53.            
  54.             seatD = Seat()
  55.             seatD.setLetter('D')
  56.             self.seats.append(seatD)
  57.            
  58.         pass
  59.  
  60.     def showEnf(self):
  61.         print(f'\nRoom No. {self.roomNo}')
  62.         print(f'availability: {self.checkAvailable()}')
  63.         for i in self.seats:
  64.             i.showinfo()
  65.             pass
  66.         pass
  67.  
  68.     def checkAvailable(self):
  69.         for i in self.seats:
  70.             if i.checkAvailable():
  71.                 return i.checkAvailable()
  72.             pass
  73.  
  74.         return False
  75.    
  76.  
  77.  
  78.  
  79.  
  80.     pass
  81.  
  82. listOfRooms = list()
  83.  
  84. for i in range(4):
  85.     roomm = Room()
  86.     roomm.setNumber((i+501))
  87.     listOfRooms.append(roomm)
  88.     del roomm
  89.     pass
  90. # rooms ready {501,502,503,504}
  91. '''
  92. for i in listOfRooms:
  93.    i.showEnf()
  94.    pass
  95. '''
  96. while True:
  97.     print('\nWhat action do you want to do?')
  98.     print('1. assign a seat to a student')
  99.     print('2. change the seat of a student')
  100.     print('3. cancel seat of a student')
  101.     print('4. find student at a certain seat')
  102.     print('5. exit')
  103.     choice = int(input())
  104.     ##1. The user will assign the seat number according to the student ID and before
  105.     #assigning the seat, the user should check whether this room is available or not.
  106.     if choice == 1:
  107.         for ru in listOfRooms:
  108.             if ru.checkAvailable():
  109.                 print(f"roomNo. {ru.roomNo} is available")
  110.                 studID = input("Enter the ID of the student: ")
  111.                 for sit in ru.seats:
  112.                     if sit.checkAvailable():
  113.                         sit.enterStudent(studID)
  114.                         pass
  115.                     break
  116.                 break
  117.            
  118.             pass
  119.  
  120.         else:
  121.             print("Hall is full! Can't enter student")
  122.             pass
  123.    
  124.         pass
  125.     if choice == 5:
  126.         exit(0)
  127.         break
  128.  
  129.  
  130.     pass
  131.  
  132.  
Advertisement
Add Comment
Please, Sign In to add comment