Using python , write a program to assign passaengers seats in an airplane. Assum
ID: 3832200 • Letter: U
Question
Using python, write a program to assign passaengers seats in an airplane. Assume a small airplane with seat numbering as follows:
1 A B C D
2 A B C D
3 A B C D
4 A B C D
5 A B C D
6 A B C D
The program should display the seat pattern, with an X amrking the seats already assgned. For example, after seats 1A, 2B, and 4C are taken, the display should look like this:
1 X B C D
2 A X C D
3 A B C D
4 A B X D
5 A B C D
6 A B C D
After displaying the seats available the program prompts for the seat desired the user types in a seat, and then the display of available seats is updated. This countinues until all seats are filled or until the user signals that the program should end. If the user enter the seat number XX, the program should end. If the user types in a seat that is already assigned, the program should say that that seat is occupied and ask for another choice.
Explanation / Answer
def displaySeats(seats):
for i in range(0, len(seats)):
print(str(i+1) + " "),
for j in range(0, len(seats[i])):
print(seats[i][j] + " "),
print("")
def main():
seats = []
for i in range(0, 6):
seats.append(['A', 'B', 'C', 'D'])
while True:
displaySeats(seats)
choice = input("Enter seat: ")
choice = choice.upper()
if choice == "XX":
break
if not choice[0].isdigit():
print("Enter a valid seat number")
continue
row = int(choice[0])
if row < 1 or row > 6:
print("Please select from row 1 to 6 only")
continue
if choice[1] < "A" or choice[1] > "D":
print("Please select seat from A to D only")
continue
seatNumber = ord(choice[1]) - ord('A')
row = row -1
if seats[row][seatNumber] == 'X':
print("Seat already booked. Try again")
continue
else:
seats[row][seatNumber] = 'X'
main()
# Code link: https://paste.ee/p/rY9Wh
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.