Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Seat():
- def __init__(self):
- self.letter = "A"
- self.available = True
- self.studID = None
- def setLetter(self, letter):
- self.letter = letter
- pass
- def checkAvailable(self):
- return self.available
- pass
- def enterStudent(self, studID):
- self.studID = studID
- self.available = False
- pass
- def exitStudent(self):
- self.studID = None
- self.available = True
- pass
- def showinfo(self):
- print(f'\nseat: {self.letter}')
- print(f'availability: {self.checkAvailable()}')
- if self.available:
- print(f'Student residing: {self.studID}')
- class Room():
- def __init__(self):
- self.roomNo = "###"
- self.seats = list()
- seatA = Seat()
- seatA.setLetter('A')
- self.seats.append(seatA)
- seatB = Seat()
- seatB.setLetter('B')
- self.seats.append(seatB)
- def setNumber(self, number):
- self.roomNo = number
- if self.roomNo in (501, 502, 504):
- seatC = Seat()
- seatC.setLetter('C')
- self.seats.append(seatC)
- seatD = Seat()
- seatD.setLetter('D')
- self.seats.append(seatD)
- pass
- def showEnf(self):
- print(f'\nRoom No. {self.roomNo}')
- print(f'availability: {self.checkAvailable()}')
- for i in self.seats:
- i.showinfo()
- pass
- pass
- def checkAvailable(self):
- for i in self.seats:
- if i.checkAvailable():
- return i.checkAvailable()
- pass
- return False
- pass
- listOfRooms = list()
- for i in range(4):
- roomm = Room()
- roomm.setNumber((i+501))
- listOfRooms.append(roomm)
- del roomm
- pass
- # rooms ready {501,502,503,504}
- '''
- for i in listOfRooms:
- i.showEnf()
- pass
- '''
- while True:
- print('\nWhat action do you want to do?')
- print('1. assign a seat to a student')
- print('2. change the seat of a student')
- print('3. cancel seat of a student')
- print('4. find student at a certain seat')
- print('5. exit')
- choice = int(input())
- ##1. The user will assign the seat number according to the student ID and before
- #assigning the seat, the user should check whether this room is available or not.
- if choice == 1:
- for ru in listOfRooms:
- if ru.checkAvailable():
- print(f"roomNo. {ru.roomNo} is available")
- studID = input("Enter the ID of the student: ")
- for sit in ru.seats:
- if sit.checkAvailable():
- sit.enterStudent(studID)
- pass
- break
- break
- pass
- else:
- print("Hall is full! Can't enter student")
- pass
- pass
- if choice == 5:
- exit(0)
- break
- pass
Advertisement
Add Comment
Please, Sign In to add comment