Я работаю над заданием, которое бронирует места на рейсе, код, который у меня есть, пока работает для всего, кроме части для сброса всех мест, доступных, когда рейс полностью забронирован.
NUM_ROWS = 2
NUM_COLS = 1
AVAIL = '-'
BOOKED = 'X'
seatTable = []
for i in range(NUM_ROWS):
column = []
for j in range(NUM_COLS):
column.append(AVAIL)
seatTable.append(column)
def resetTable(seats): ##<--need to fix
seatTable = []
for i in range(NUM_ROWS):
column = []
for j in range(NUM_COLS):
column.append(AVAIL)
seatTable.append(column)
resetTable(printTable(seatTable)) ##<-- not correct
print()
def printTable(seats):
i=1
alpha = 'abcdefghijklmnopqrstuvwxyz'
print('Row', end=' ')
for num in range(NUM_COLS):
print(f'{alpha[num]:2s}'.format(alpha),end='')
print()
for num in seats:
print(f'{str(i):3s}'.format(str(i)), end=' ')
i+=1
for j in num:
print(j,end=' ')
print()
def full(seats):
for row in seats:
for seat in row:
if seat == AVAIL:
return False
return True
def getRes():
alpha = 'abcdefghijklmnopqrstuvwxyz'
while True:
try:
rowNum = input(f'Enter a row number (1 to {NUM_ROWS}): ')
seatLetter = input(f'Enter a seat letter (A to {(alpha[NUM_COLS-1]).upper()}): ')
reserve(seatTable,rowNum,seatLetter)
break
except:
pass
print('Error, Please choose another seat')
print(f'Seat {rowNum}{seatLetter.upper()} has been booked\n')
def reserve(seats,resR,resC):
alpha = 'abcdefghijklmnopqrstuvwxyz'
column = 0
p = 0
for i in alpha:
if i.lower() == resC.lower():
column = p
p+=1
row = int(resR)-1
seats[row][column] = BOOKED
def main():
printTable(seatTable)
while not full(seatTable):
getRes()
printTable(seatTable)
print('Plane is booked')
next = input('\nWould you like to check the next flight? (Y/N): ')
if next == 'y': ##<---problem
resetTable(printTable(seatTable))
return main()
else:
exit()
main()
Когда я запускаю код для проверки «следующего рейса», места сбрасываются, но затем замирает на бесконечном l oop, за которым следует ошибка:
line 23, in resetTable
resetTable(printTable(seatTable)) ##<-- not correct
[Previous line repeated 992 more times]
RecursionError: maximum recursion depth exceeded while calling a Python object
Как мне исправить resetTable()
функция для работы?