Skip to content

Instantly share code, notes, and snippets.

@devpruthvi
Last active August 29, 2015 14:07
Show Gist options
  • Save devpruthvi/00c8df9ec6b6f573b51f to your computer and use it in GitHub Desktop.
Save devpruthvi/00c8df9ec6b6f573b51f to your computer and use it in GitHub Desktop.
Airline after some corrections
firstclass = [0]*8 #list that stores first class data
economyclass = [0]*8 #list that stores economy class data
booked = {} #Stores names and seat numbers of booked people
def displayseats(): #This will display seats in a formatted way
print("First Class Economy Class")
for each in range(0,4):
if firstclass[each] == 0:
print("(" +str(each+1) + ")", end='')
else:
print("(X)", end='')
print(" ",end='')
if(firstclass[each+4] == 0):
print("(" + str(each+5) + ")",end='')
else:
print("(X)",end='')
print(" ",end='')
if economyclass[each] == 0:
print("[" +str(each+1+8) + "]",end='')
else:
print("(X)", end='')
print(" ",end='')
if(economyclass[each+4] == 0):
print("[" + str(each+5+8) + "]")
else:
print("[X]")
def bookseat(name):
displayseats() #This will book the seat
a = input("Enter 1 for First Class and 2 for Economy Class: ")
while (not a.isdigit()) or (int(a) != 1 and int(a) != 2):
a = input("Please enter a valid option: ")
clas = int(a)
if clas==1:
stringseatno= input("Enter the seat number(1-8): ")
while not stringseatno.isdigit() or int(stringseatno) not in range(1,9) or int(stringseatno) in booked.values():
stringseatno = input("Please enter valid seat number: ")
while not stringseatno.isdigit():
stringseatno = input("Enter a valid number: ")
seatno = int(stringseatno)
firstclass[seatno-1] = 1
booked[name] = seatno
elif clas==2:
stringseatno= input("Enter the seat number(9-16): ")
while not stringseatno.isdigit() or int(stringseatno) not in range(9,17) or int(stringseatno) in booked.values():
stringseatno = input("Please enter valid seat number: ")
while not stringseatno.isdigit():
stringseatno = input("Enter a valid number: ")
seatno = int(stringseatno)
economyclass[seatno-9] = 1
booked[name] = seatno
def showbooked(): #This will show the booked seat
print("Seat Number Name")
for key,value in booked.items():
print(str(value) + " "*13 + str(key))
def showmenu():
name = input("Enter your name: ")
bookseat(name) #This is the main driver function which calls others!
while True:
displayseats()
print("1.Book Seat\n2.Show Booked\n3.Exit\n Enter your option: ")
a = input()
while (not a.isdigit()) or ( int(a) != 1 and int(a) != 2 and int(a) != 3):
a = input("Please enter a valid option: ")
x = int(a)
if x == 1:
name = input("Enter your name: ")
bookseat(name)
elif x == 2:
showbooked()
elif x == 3:
break
return
showmenu()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment