Skip to content

Instantly share code, notes, and snippets.

@devpruthvi
Created October 2, 2014 18:53
Show Gist options
  • Save devpruthvi/911c0ccf95cc2233ced9 to your computer and use it in GitHub Desktop.
Save devpruthvi/911c0ccf95cc2233ced9 to your computer and use it in GitHub Desktop.
firstclass = [0,0,0,0,0,0,0,0] #list that stores first class data
economyclass = [0,0,0,0,0,0,0,0] #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():
a = input("Please enter a valid option: ")
clas = int(a)
if clas==1:
seatno = int(input("Enter the seat number: "))
while seatno not in range(1,9) or seatno in booked.values():
print("Invalid seat number")
if seatno in booked.values():
print("Seat has already booked")
seatno = int(input("Enter valid seat number: "))
firstclass[seatno-1] = 1
booked[name] = seatno
elif clas==2:
seatno = int(input("Enter the seat number: "))
while seatno not in range(9,17) or seatno in booked.values():
print("Invalid seat number")
if seatno in booked.values():
print("Seat has already been booked")
seatno = int(input("Enter valid seat number: "))
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():
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
else:
while(x != 1 or x != 2 or x != 3):
x = int(input("Enter valid option: "))
return
showmenu()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment