Advertisement
Guest User

Airplane seating python

a guest
Apr 8th, 2020
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.78 KB | None | 0 0
  1. NUM_ROWS = 2
  2. NUM_COLS = 1
  3. AVAIL = '-'
  4. BOOKED = 'X'
  5.  
  6. seatTable = []
  7. for i in range(NUM_ROWS):
  8.     column = []
  9.     for j in range(NUM_COLS):
  10.         column.append(AVAIL)
  11.     seatTable.append(column)
  12.  
  13. def resetTable(seats):          ##needs to set all seats to available
  14.     seatTable = []
  15.     for i in range(NUM_ROWS):
  16.         column = []
  17.         for j in range(NUM_COLS):
  18.             column.append(AVAIL)
  19.         seatTable.append(column)
  20.     resetTable(printTable(seatTable))   ##<-- not correct
  21.     print()
  22.  
  23. def printTable(seats):
  24.     i=1
  25.     alpha = 'abcdefghijklmnopqrstuvwxyz'
  26.     print('Row', end=' ')
  27.  
  28.     for num in range(NUM_COLS):
  29.         print(f'{alpha[num]:2s}'.format(alpha),end='')
  30.     print()
  31.  
  32.     for num in seats:
  33.         print(f'{str(i):3s}'.format(str(i)), end=' ')
  34.         i+=1
  35.         for j in num:
  36.             print(j,end=' ')
  37.         print()
  38.  
  39. def full(seats):
  40.     for row in seats:
  41.         for seat in row:
  42.             if seat == AVAIL:
  43.                 return False
  44.     return True
  45.  
  46. def getRes():
  47.     alpha = 'abcdefghijklmnopqrstuvwxyz'
  48.     while True:
  49.         try:
  50.             rowNum = input(f'Enter a row number (1 to {NUM_ROWS}): ')
  51.             seatLetter = input(f'Enter a seat letter (A to {(alpha[NUM_COLS-1]).upper()}): ')
  52.             reserve(seatTable,rowNum,seatLetter)
  53.             break
  54.         except:
  55.             pass
  56.         print('Error, Please choose another seat')
  57.     print(f'Seat {rowNum}{seatLetter.upper()} has been booked\n')
  58.  
  59. def reserve(seats,resR,resC):
  60.     alpha = 'abcdefghijklmnopqrstuvwxyz'
  61.     column = 0
  62.     p = 0
  63.     for i in alpha:
  64.         if i.lower() == resC.lower():
  65.             column = p
  66.         p+=1
  67.     row = int(resR)-1
  68.     seats[row][column] = BOOKED
  69.  
  70.  
  71.  
  72. def main():
  73.     printTable(seatTable)
  74.     while not full(seatTable):
  75.         getRes()
  76.         printTable(seatTable)
  77.     print('Plane is booked')
  78.     next = input('\nWould you like to check the next flight? (Y/N): ')
  79.     if next == 'y':
  80.         resetTable(printTable(seatTable))
  81.         return main()
  82.     else:
  83.         exit()
  84.  
  85. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement