Skip to content

Commit 96470a9

Browse files
authored
add features
logs: minor changes: Comments for each section changed major changes: • different name accepted for each seat • different phone numbers accepted for each seat
1 parent 777516c commit 96470a9

File tree

1 file changed

+79
-72
lines changed

1 file changed

+79
-72
lines changed

aeroplane_seat_reservation_system.py

+79-72
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
from datetime import date
1111

12-
# declaring global variables
13-
name = "username"
14-
phone_number = 0000000000
12+
# declaring global variables -------------------------------------------------------------------------------
13+
name = ["username"] * 28
14+
phone_number = [000000000] * 28
1515
travel_date = "dd mm yyyy"
1616
travel_time = "00:00"
1717

@@ -22,11 +22,12 @@
2222

2323
total_number_of_seats = 0
2424
terminator = 0
25+
current_user_number = 0
2526
current_location = "unknown"
2627
destination = "unknown"
2728
cost = 0.0
2829

29-
# declaring variables to print the seating pattern
30+
# declaring variables to print the seating pattern ---------------------------------------------------------
3031
occupied_seats = [True, False, # row 1
3132
False, True, # row 2
3233
True, True, False, True, # row 3
@@ -43,7 +44,7 @@
4344
"9A", "9B", "9C", "9D", "9E", "9F", "10A", "10B", "10C", "10D", "10E", "10F",
4445
"11A", "11B", "11C", "11D", "11E", "11F"]
4546

46-
# declaring global variables to accept the seat from the user
47+
# declaring global variables to accept the seat from the user --------------------------------------------
4748
number_of_seats_booked = 0
4849
users_seat = ["nothing here"] * 28
4950
all_seats_index = 0
@@ -61,64 +62,22 @@ def display_welcome():
6162
f"We would like to take some information:{bcolors.ENDC}{bcolors.ENDC}{bcolors.ENDC}")
6263

6364

64-
# accepting the users name
65-
def accept_name():
66-
global name
67-
68-
name = input("Your name please: ") # accepting the users name
69-
name.strip() # removing unwanted spaces before and after the name
70-
name = name + " " # adding a space after the name
71-
72-
# declaration
73-
word = ""
74-
new_name = ""
75-
76-
# capitalizing name
77-
for i in range(0, len(name)):
78-
ch = name[i]
79-
word = word + ch
80-
81-
if ch == ' ':
82-
word = word.capitalize()
83-
new_name = new_name + word
84-
word = ""
85-
86-
name = new_name
87-
88-
89-
# accepting other details from the user like his phone number, current location and destination
90-
def other_details():
91-
global phone_number
65+
def constant_details():
9266
global total_number_of_seats
67+
global terminator
9368
global current_location
9469
global destination
9570
global travel_date
9671
global today_date
9772
global travel_time
9873
global today_time
99-
global terminator
10074

101-
# accepting the phone number of the user
102-
phone_number = input("Enter your phone number: ")
103-
104-
while True:
105-
if not phone_number.isdigit():
106-
phone_number = input(f"{bcolors.WARNING}Looks like your phone number has alphabets... "
107-
f"Please enter the correct value: {bcolors.ENDC}")
108-
else:
109-
break
110-
111-
while len(phone_number) != 10:
112-
print("Please make sure that the phone number that you have entered is 10 digits long")
113-
print("The phone number you entered was " + str(len(phone_number)) + " digits long ")
114-
phone_number = input("Please enter the phone number: ")
115-
116-
# accepting the total number of seats the user wants to book
75+
# accepting the total number of seats the user wants to book --------------------------------------------
11776
total_number_of_seats = input("Total number of reservations: ")
11877

11978
available_number_of_seats = 0
12079

121-
for i in range(0, len(occupied_seats)):
80+
for i in range(0, len(occupied_seats)): # finding the available number of seats
12281
if occupied_seats[i]:
12382
available_number_of_seats += 1
12483

@@ -136,9 +95,10 @@ def other_details():
13695

13796
# declaring the value of terminator
13897
terminator = int(total_number_of_seats)
98+
terminator = terminator - 1
13999

140100
while True:
141-
# accepting the date of travel
101+
# accepting the date of travel ----------------------------------------------------------------------
142102
dt, mt, yt = [int(x) for x in input("Enter Travel Date (dd/mm/yyyy): ").split('/')]
143103
travel_date = date(yt, mt, dt)
144104

@@ -151,6 +111,9 @@ def other_details():
151111
its_a_proper_date = False
152112
its_an_invalid_date = True
153113

114+
if int(today_date.month) == int(mt):
115+
its_a_proper_date = True
116+
154117
if int(today_date.year) == int(yt) and int(today_date.month) == int(mt) and int(today_date.day) == int(dt):
155118
its_todays_date = True
156119
its_an_invalid_date = False
@@ -207,24 +170,69 @@ def other_details():
207170
print(f"{bcolors.WARNING}Looks like you are from the past...{bcolors.ENDC}")
208171
continue
209172

210-
# accepting the current location
173+
# accepting the current location ------------------------------------------------------------------
211174
current_location = input("From: ")
212175

213-
# accepting the destination
176+
# accepting the destination -----------------------------------------------------------------------
214177
destination = input("To: ")
215178

216179
# converting current_location and destination into upper case
217180
current_location = current_location.capitalize()
218181
destination = destination.capitalize()
219182

220183

184+
def variable_information():
185+
global name
186+
global phone_number
187+
global current_user_number
188+
189+
# accepting the name of the user
190+
name[current_user_number] = input("Your name please: ") # accepting the users name
191+
name[current_user_number].strip() # removing unwanted spaces before and after the name
192+
name[current_user_number] = name[current_user_number] + " " # adding a space after the name
193+
194+
# declaration
195+
name_operator = name[current_user_number]
196+
word = ""
197+
new_name = ""
198+
199+
# capitalizing name ----------------------------------------------------------------------------
200+
for i in range(0, len(name_operator)):
201+
ch = name_operator[i]
202+
word = word + ch
203+
204+
if ch == ' ':
205+
word = word.capitalize()
206+
new_name = new_name + word
207+
word = ""
208+
209+
name[current_user_number] = new_name
210+
211+
# accepting the phone number of the user --------------------------------------------------------
212+
phone_number = input("Enter your phone number: ")
213+
214+
while True:
215+
if not phone_number.isdigit():
216+
phone_number = input(f"{bcolors.WARNING}Looks like your phone number has alphabets... "
217+
f"Please enter the correct value: {bcolors.ENDC}")
218+
else:
219+
break
220+
221+
while len(phone_number) != 10:
222+
print("Please make sure that the phone number that you have entered is 10 digits long")
223+
print("The phone number you entered was " + str(len(phone_number)) + " digits long ")
224+
phone_number = input("Please enter the phone number: ")
225+
226+
display_aeroplane_seat()
227+
228+
221229
def display_aeroplane_seat():
222230
# global variables
223231
global occupied_seats
224232
global all_seats
225233

226234
# displaying Business Class
227-
print(" " + f"{bcolors.BOLD}Business Class{bcolors.ENDC}" + " ")
235+
print(" " + f"{bcolors.BOLD}First Class{bcolors.ENDC}" + " ")
228236

229237
for i in range(0, 4):
230238
# displaying 1A and 2A with colour code
@@ -240,7 +248,7 @@ def display_aeroplane_seat():
240248
print(f"{bcolors.OKGREEN}{all_seats[i]}{bcolors.ENDC}" + " ▢", end="\n")
241249

242250
# displaying First Class
243-
print(" " + f"{bcolors.BOLD}First Class{bcolors.ENDC}" + " ")
251+
print(" " + f"{bcolors.BOLD}Business Class{bcolors.ENDC}" + " ")
244252

245253
for i in range(4, 16):
246254
# displaying 3A, 4A and 5A with colour code
@@ -347,16 +355,16 @@ def display_aeroplane_seat():
347355
accept_users_seat()
348356

349357

350-
# accepting the users seat number
351-
def accept_users_seat():
358+
def accept_users_seat(): # accepting the users seat number ---------------------------------------------------
352359
global number_of_seats_booked
353360
global users_seat
354361
global all_seats_index
355362
global occupied_seats
356363
global terminator
364+
global current_user_number
357365

358366
while True:
359-
if terminator > 0:
367+
if current_user_number <= terminator:
360368
# accepting users seat
361369
users_seat[number_of_seats_booked] = input(f"{bcolors.BOLD}Please enter the seat "
362370
f"that you want to book: {bcolors.ENDC}")
@@ -375,22 +383,22 @@ def accept_users_seat():
375383
number_of_seats_booked += 1
376384
print(
377385
f"{bcolors.OKCYAN}Your seat {users_seat[number_of_seats_booked - 1]} has been booked{bcolors.ENDC}")
378-
terminator = terminator - 1
386+
current_user_number = current_user_number + 1
379387

380388
time.sleep(3)
381389

382390
# printing 40 lines of space:
383391
print("\n" * 40)
384392

385-
if terminator > 0:
386-
display_aeroplane_seat()
393+
if current_user_number <= terminator:
394+
variable_information()
387395

388396
display_boarding_pass()
389397

390398

391-
# displaying boarding pass
392-
def display_boarding_pass():
399+
def display_boarding_pass(): # displaying boarding pass --------------------------------------------------------
393400
global users_seat
401+
global name
394402
global number_of_seats_booked
395403
global cost
396404

@@ -401,25 +409,25 @@ def display_boarding_pass():
401409
seed(10)
402410

403411
_date = str(travel_date)
412+
value = random() * 10
404413

405414
for i in range(0, number_of_seats_booked):
406-
value = random() * 10
407415

408416
# calculating the cost for the type of seat booked
409417
seat_booked = users_seat[i]
410418
seat_type = seat_booked[0]
411419

412420
if int(seat_type) <= 2:
413-
cost = 300000
421+
cost = 100000
414422
elif int(seat_type) <= 5:
415-
cost = 150000
423+
cost = 40000
416424
else:
417-
cost = 75000
425+
cost = 10000
418426

419427
# I know you want to change the travels name? ↓↓↓
420428
print(" https://github.com/voyager2005 Travels ")
421429
print(f" {bcolors.BOLD}BOARDING PASS{bcolors.ENDC} ")
422-
print(name + "\t" + "Flight: OKL012" + "\t" + users_seat[i])
430+
print(name[i] + "\t" + "Flight: OKL012" + "\t" + "Seat Number: " + users_seat[i])
423431
print(f"Gate: {int(value)}" + " " + "date: " + _date + "\t" + "cost: " + str(cost))
424432
print(f"From: {current_location} \t\t To: {destination}")
425433
print()
@@ -430,6 +438,5 @@ def display_boarding_pass():
430438
# calling the methods
431439
while True:
432440
display_welcome()
433-
accept_name()
434-
other_details()
435-
display_aeroplane_seat()
441+
constant_details()
442+
variable_information()

0 commit comments

Comments
 (0)