9
9
10
10
from datetime import date
11
11
12
- # declaring global variables
13
- name = "username"
14
- phone_number = 0000000000
12
+ # declaring global variables -------------------------------------------------------------------------------
13
+ name = [ "username" ] * 28
14
+ phone_number = [ 000000000 ] * 28
15
15
travel_date = "dd mm yyyy"
16
16
travel_time = "00:00"
17
17
22
22
23
23
total_number_of_seats = 0
24
24
terminator = 0
25
+ current_user_number = 0
25
26
current_location = "unknown"
26
27
destination = "unknown"
27
28
cost = 0.0
28
29
29
- # declaring variables to print the seating pattern
30
+ # declaring variables to print the seating pattern ---------------------------------------------------------
30
31
occupied_seats = [True , False , # row 1
31
32
False , True , # row 2
32
33
True , True , False , True , # row 3
43
44
"9A" , "9B" , "9C" , "9D" , "9E" , "9F" , "10A" , "10B" , "10C" , "10D" , "10E" , "10F" ,
44
45
"11A" , "11B" , "11C" , "11D" , "11E" , "11F" ]
45
46
46
- # declaring global variables to accept the seat from the user
47
+ # declaring global variables to accept the seat from the user --------------------------------------------
47
48
number_of_seats_booked = 0
48
49
users_seat = ["nothing here" ] * 28
49
50
all_seats_index = 0
@@ -61,64 +62,22 @@ def display_welcome():
61
62
f"We would like to take some information:{ bcolors .ENDC } { bcolors .ENDC } { bcolors .ENDC } " )
62
63
63
64
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 ():
92
66
global total_number_of_seats
67
+ global terminator
93
68
global current_location
94
69
global destination
95
70
global travel_date
96
71
global today_date
97
72
global travel_time
98
73
global today_time
99
- global terminator
100
74
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 --------------------------------------------
117
76
total_number_of_seats = input ("Total number of reservations: " )
118
77
119
78
available_number_of_seats = 0
120
79
121
- for i in range (0 , len (occupied_seats )):
80
+ for i in range (0 , len (occupied_seats )): # finding the available number of seats
122
81
if occupied_seats [i ]:
123
82
available_number_of_seats += 1
124
83
@@ -136,9 +95,10 @@ def other_details():
136
95
137
96
# declaring the value of terminator
138
97
terminator = int (total_number_of_seats )
98
+ terminator = terminator - 1
139
99
140
100
while True :
141
- # accepting the date of travel
101
+ # accepting the date of travel ----------------------------------------------------------------------
142
102
dt , mt , yt = [int (x ) for x in input ("Enter Travel Date (dd/mm/yyyy): " ).split ('/' )]
143
103
travel_date = date (yt , mt , dt )
144
104
@@ -151,6 +111,9 @@ def other_details():
151
111
its_a_proper_date = False
152
112
its_an_invalid_date = True
153
113
114
+ if int (today_date .month ) == int (mt ):
115
+ its_a_proper_date = True
116
+
154
117
if int (today_date .year ) == int (yt ) and int (today_date .month ) == int (mt ) and int (today_date .day ) == int (dt ):
155
118
its_todays_date = True
156
119
its_an_invalid_date = False
@@ -207,24 +170,69 @@ def other_details():
207
170
print (f"{ bcolors .WARNING } Looks like you are from the past...{ bcolors .ENDC } " )
208
171
continue
209
172
210
- # accepting the current location
173
+ # accepting the current location ------------------------------------------------------------------
211
174
current_location = input ("From: " )
212
175
213
- # accepting the destination
176
+ # accepting the destination -----------------------------------------------------------------------
214
177
destination = input ("To: " )
215
178
216
179
# converting current_location and destination into upper case
217
180
current_location = current_location .capitalize ()
218
181
destination = destination .capitalize ()
219
182
220
183
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
+
221
229
def display_aeroplane_seat ():
222
230
# global variables
223
231
global occupied_seats
224
232
global all_seats
225
233
226
234
# displaying Business Class
227
- print (" " + f"{ bcolors .BOLD } Business Class{ bcolors .ENDC } " + " " )
235
+ print (" " + f"{ bcolors .BOLD } First Class{ bcolors .ENDC } " + " " )
228
236
229
237
for i in range (0 , 4 ):
230
238
# displaying 1A and 2A with colour code
@@ -240,7 +248,7 @@ def display_aeroplane_seat():
240
248
print (f"{ bcolors .OKGREEN } { all_seats [i ]} { bcolors .ENDC } " + " ▢" , end = "\n " )
241
249
242
250
# displaying First Class
243
- print (" " + f"{ bcolors .BOLD } First Class{ bcolors .ENDC } " + " " )
251
+ print (" " + f"{ bcolors .BOLD } Business Class{ bcolors .ENDC } " + " " )
244
252
245
253
for i in range (4 , 16 ):
246
254
# displaying 3A, 4A and 5A with colour code
@@ -347,16 +355,16 @@ def display_aeroplane_seat():
347
355
accept_users_seat ()
348
356
349
357
350
- # accepting the users seat number
351
- def accept_users_seat ():
358
+ def accept_users_seat (): # accepting the users seat number ---------------------------------------------------
352
359
global number_of_seats_booked
353
360
global users_seat
354
361
global all_seats_index
355
362
global occupied_seats
356
363
global terminator
364
+ global current_user_number
357
365
358
366
while True :
359
- if terminator > 0 :
367
+ if current_user_number <= terminator :
360
368
# accepting users seat
361
369
users_seat [number_of_seats_booked ] = input (f"{ bcolors .BOLD } Please enter the seat "
362
370
f"that you want to book: { bcolors .ENDC } " )
@@ -375,22 +383,22 @@ def accept_users_seat():
375
383
number_of_seats_booked += 1
376
384
print (
377
385
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
379
387
380
388
time .sleep (3 )
381
389
382
390
# printing 40 lines of space:
383
391
print ("\n " * 40 )
384
392
385
- if terminator > 0 :
386
- display_aeroplane_seat ()
393
+ if current_user_number <= terminator :
394
+ variable_information ()
387
395
388
396
display_boarding_pass ()
389
397
390
398
391
- # displaying boarding pass
392
- def display_boarding_pass ():
399
+ def display_boarding_pass (): # displaying boarding pass --------------------------------------------------------
393
400
global users_seat
401
+ global name
394
402
global number_of_seats_booked
395
403
global cost
396
404
@@ -401,25 +409,25 @@ def display_boarding_pass():
401
409
seed (10 )
402
410
403
411
_date = str (travel_date )
412
+ value = random () * 10
404
413
405
414
for i in range (0 , number_of_seats_booked ):
406
- value = random () * 10
407
415
408
416
# calculating the cost for the type of seat booked
409
417
seat_booked = users_seat [i ]
410
418
seat_type = seat_booked [0 ]
411
419
412
420
if int (seat_type ) <= 2 :
413
- cost = 300000
421
+ cost = 100000
414
422
elif int (seat_type ) <= 5 :
415
- cost = 150000
423
+ cost = 40000
416
424
else :
417
- cost = 75000
425
+ cost = 10000
418
426
419
427
# I know you want to change the travels name? ↓↓↓
420
428
print (" https://github.com/voyager2005 Travels " )
421
429
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 ])
423
431
print (f"Gate: { int (value )} " + " " + "date: " + _date + "\t " + "cost: " + str (cost ))
424
432
print (f"From: { current_location } \t \t To: { destination } " )
425
433
print ()
@@ -430,6 +438,5 @@ def display_boarding_pass():
430
438
# calling the methods
431
439
while True :
432
440
display_welcome ()
433
- accept_name ()
434
- other_details ()
435
- display_aeroplane_seat ()
441
+ constant_details ()
442
+ variable_information ()
0 commit comments