Summiya14Fis14Samaa

mid 2c completed

Dec 18th, 2021
1,429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.72 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 not 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. global listOfRooms
  83. listOfRooms = list()
  84.  
  85. for i in range(4):
  86.     roomm = Room()
  87.     roomm.setNumber((i+501))
  88.     listOfRooms.append(roomm)
  89.     del roomm
  90.     pass
  91. # rooms ready {501,502,503,504}
  92. '''
  93. for i in listOfRooms:
  94.    i.showEnf()
  95.    pass
  96. '''
  97. while True:
  98.     print('\nWhat action do you want to do?')
  99.     print('1. assign a seat to a student')
  100.     print('2. change the seat of a student')
  101.     print('3. cancel seat of a student')
  102.     print('4. find student at a certain seat')
  103.     print('5. exit')
  104.     choice = int(input())
  105.     ##1. The user will assign the seat number according to the student ID and before
  106.     #assigning the seat, the user should check whether this room is available or not.
  107.     if choice == 1:
  108.         i=0
  109.         for ru in listOfRooms:
  110.             if ru.checkAvailable():
  111.                 print(f"roomNo. {ru.roomNo} is available")
  112.                 studID = input("Enter the ID of the student: ")
  113.                 j = 0
  114.  
  115.                 for sit in ru.seats:
  116.                     if sit.checkAvailable():
  117.                         #sit.enterStudent(studID)
  118.                         listOfRooms[i].seats[j].enterStudent(studID)
  119.                         listOfRooms[i].showEnf()
  120.                         ru.showEnf()
  121.                         pass
  122.                     break
  123.                 break
  124.            
  125.             pass
  126.  
  127.         else:
  128.             print("Hall is full! Can't enter student")
  129.             pass
  130.         i += 1
  131.    
  132.         pass
  133.        
  134.     ##2. The user can change the seat of the students if and only if the seats are
  135.     #available.
  136.     elif choice == 2:
  137.         print("enter Id of student to shift")
  138.         studID = input()
  139.         foundS = 0
  140.         for ru in listOfRooms:
  141.             for sit in ru.seats:
  142.                 if sit.studID == studID:
  143.                     sit.exitStudent()
  144.                     ru.showEnf()
  145.                     foundS = 1
  146.                     break
  147.                 pass
  148.  
  149.             if foundS == 1:
  150.                 break
  151.             pass
  152.  
  153.         moved = 0
  154.  
  155.  
  156.         for ru in listOfRooms:
  157.             if ru.checkAvailable():
  158.                 for sit in ru.seats:
  159.                     if sit.checkAvailable():
  160.                         sit.enterStudent(studID)
  161.                         ru.showEnf()
  162.                         moved = 1
  163.                         break
  164.                 pass
  165.                          
  166.             if moved == 1:
  167.                 break    
  168.             else:
  169.                 continue
  170.  
  171.         else:
  172.             print("Hall is Full can't change seats")
  173.            
  174.         pass
  175.     ##3. The user can cancel the seat of the students who passed out and make them
  176.     #available to others.
  177.     elif choice == 3:
  178.         studID = input("Enter the ID of the student whose seat is to be canceled: ")
  179.         moved = 0
  180.         for ru in listOfRooms:
  181.             for sit in ru.seats:
  182.                 if sit.studID == studID:
  183.                     sit.exitStudent()
  184.                     ru.showEnf()
  185.                     moved = 1
  186.                     break
  187.                 pass
  188.             if moved == 1:
  189.                 break
  190.        
  191.             pass
  192.        
  193.         pass
  194.  
  195.     ##4. For any emergency purpose, the user will be able to find the student in a
  196.     #particular seat
  197.     elif choice == 4:
  198.         seatNo = input("Enter the seat you need to find student info on: ")
  199.         ruNo = int(seatNo[:-1])
  200.         seatNo = seatNo[-1]
  201.         found = 0
  202.         for ru in listOfRooms:
  203.             if ru.roomNo == ruNo:
  204.                 for sit in ru.seats:
  205.                     if seatNo == sit.Letter:
  206.                         print(f"Student ID of student at {ruNo}{seatNo} is: {sit.studID}")
  207.                         found = 1
  208.                         break
  209.                     pass
  210.                 pass
  211.             if found == 1:
  212.                 break
  213.             pass
  214.         pass
  215.  
  216.     elif choice == 5:
  217.         exit(0)
  218.         break
  219.  
  220.     pass
  221.  
  222.  
Advertisement
Add Comment
Please, Sign In to add comment