Skip to content

Instantly share code, notes, and snippets.

@anasAlsalol
Created November 5, 2019 07:48
Show Gist options
  • Select an option

  • Save anasAlsalol/cd2f533625dfbc8677b7583d7cdf1a53 to your computer and use it in GitHub Desktop.

Select an option

Save anasAlsalol/cd2f533625dfbc8677b7583d7cdf1a53 to your computer and use it in GitHub Desktop.
# import numpy
# numpy.arange(1,29)
seat = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28]
reserved_seat = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
def count_available_seat():
count = 0
for i in range(len(reserved_seat)):
if reserved_seat[i] == 0:
count = count + 1
print(f'the Number of available seat {count:^20}', end='\n')
def create_seat():
f = open("seat.txt", "w+")
for i in range(len(reserved_seat)):
split = i + 1
if reserved_seat[i] == 0:
f.write("%d\t" % 0)
else:
f.write("%d\t" % 1)
if split % 4 == 0:
f.write("\n")
f.close()
# read_seat_from_file()
def read_seat_from_file():
global reserved_seat
seat_file = open("seat.txt")
iteration = 0
for line in seat_file:
index = iteration
for item in line.split('\t'):
if item == "\n":
continue
reserved_seat[index] = int(item)
index = index + 1
iteration = iteration + 4
seat_file.close()
def init_seat_file():
try:
f = open("seat.txt")
f.close()
read_seat_from_file()
except FileNotFoundError:
create_seat()
def display_seat_status():
for i in range(len(reserved_seat)):
split = i + 1
if reserved_seat[i] == 0:
print(f'[{seat[i]:^15}]', end='', )
elif reserved_seat[i] == 1:
print(f'{"Reserved":^17}', end='')
if split % 4 == 0:
print()
# return key if Reserved , else return -1
def find_seat(key):
for i in range(len(reserved_seat)):
if reserved_seat[key - 1] == 1:
return key
return -1
def do_reserved_seat(key):
# global SeatAvail
global reserved_seat
if find_seat(key) < 0:
reserved_seat[key - 1] = 1
# SeatAvail = SeatAvail - 1
create_seat()
else:
print("already Reserved ")
def delete_seat(key):
# global SeatAvail
global reserved_seat
if find_seat(key) > 0:
reserved_seat[key - 1] = 0
create_seat()
# SeatAvail = SeatAvail + 1
else:
print("Not Reserved")
def check_enter_key():
key = input("Press Enter to Continue -")
while key:
invalid_action()
key = input("Press Enter to Continue - ")
return True
'''
def enterkey():
key = input("Press Enter to Continue : ")
return True
print(key)
if key == "enter":
return True
return False
'''
def invalid_action():
print("invalid Action")
def list_reserve_seat():
display_seat_status()
count_available_seat()
seat_number = input("Please Enter required Number Of Seat ")
# print(int(choice))
# if int(choice) in range(len(booked_Matrix)):
do_reserved_seat(int(seat_number))
# else:
# print("out Of Range")
def list_delete_seat():
display_seat_status()
count_available_seat()
seat_number = input("Please Enter required Number Of Seat ")
# if int(choice) in range(len(booked_Matrix)):
delete_seat(int(seat_number))
# else:
# print("out Of Range")
init_seat_file()
flag = True
while flag:
# DisplaySeats();
print('''Hello Welcome to Bus seats:
1: Display number of available seats.
2: Display seat status for all seats.
3: Reserve seat(s).
4: Delete reservation(s).
5: Exit.''')
action = input("Please select your choice [1,2,3,4 or 5]: ")
print(action)
if action == "1":
count_available_seat()
check_enter_key()
'''if check_enter_key():
print(action)
else:
invalid_action()'''
elif action == "2":
display_seat_status()
check_enter_key()
'''if check_enter_key():
print(action)
else:
invalid_action()'''
elif action == "3":
list_reserve_seat()
check_enter_key()
'''if check_enter_key():
print(action)
else:
invalid_action()'''
elif action == "4":
list_delete_seat()
check_enter_key()
'''if check_enter_key():
print(action)
else:
invalid_action()'''
elif action == "5":
flag = False
print("THANK YOU")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment