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 not 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
- global listOfRooms
- 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:
- i=0
- for ru in listOfRooms:
- if ru.checkAvailable():
- print(f"roomNo. {ru.roomNo} is available")
- studID = input("Enter the ID of the student: ")
- j = 0
- for sit in ru.seats:
- if sit.checkAvailable():
- #sit.enterStudent(studID)
- listOfRooms[i].seats[j].enterStudent(studID)
- listOfRooms[i].showEnf()
- ru.showEnf()
- pass
- break
- break
- pass
- else:
- print("Hall is full! Can't enter student")
- pass
- i += 1
- pass
- ##2. The user can change the seat of the students if and only if the seats are
- #available.
- elif choice == 2:
- print("enter Id of student to shift")
- studID = input()
- foundS = 0
- for ru in listOfRooms:
- for sit in ru.seats:
- if sit.studID == studID:
- sit.exitStudent()
- ru.showEnf()
- foundS = 1
- break
- pass
- if foundS == 1:
- break
- pass
- moved = 0
- for ru in listOfRooms:
- if ru.checkAvailable():
- for sit in ru.seats:
- if sit.checkAvailable():
- sit.enterStudent(studID)
- ru.showEnf()
- moved = 1
- break
- pass
- if moved == 1:
- break
- else:
- continue
- else:
- print("Hall is Full can't change seats")
- pass
- ##3. The user can cancel the seat of the students who passed out and make them
- #available to others.
- elif choice == 3:
- studID = input("Enter the ID of the student whose seat is to be canceled: ")
- moved = 0
- for ru in listOfRooms:
- for sit in ru.seats:
- if sit.studID == studID:
- sit.exitStudent()
- ru.showEnf()
- moved = 1
- break
- pass
- if moved == 1:
- break
- pass
- pass
- ##4. For any emergency purpose, the user will be able to find the student in a
- #particular seat
- elif choice == 4:
- seatNo = input("Enter the seat you need to find student info on: ")
- ruNo = int(seatNo[:-1])
- seatNo = seatNo[-1]
- found = 0
- for ru in listOfRooms:
- if ru.roomNo == ruNo:
- for sit in ru.seats:
- if seatNo == sit.Letter:
- print(f"Student ID of student at {ruNo}{seatNo} is: {sit.studID}")
- found = 1
- break
- pass
- pass
- if found == 1:
- break
- pass
- pass
- elif choice == 5:
- exit(0)
- break
- pass
Advertisement
Add Comment
Please, Sign In to add comment