1- def menu ():
2- print ("" )
3- print ("" )
4- print (" Welcome to Hotel Database Management Software" )
5- print ("" )
6- print ("" )
7-
8- print ("1-Add new customer details" )
9- print ("2-Modify already existing customer details" )
10- print ("3-Search customer details" )
11- print ("4-View all customer details" )
12- print ("5-Delete customer details" )
13- print ("6-Exit the program" )
14- print ("" )
15-
16- user_input = int (input ("Enter your choice(1-6): " ))
17-
18- if user_input == 1 :
19- add ()
201
21- elif user_input == 2 :
22- modify ()
2+ def menu ():
233
24- elif user_input == 3 :
25- search ()
4+ options = {
5+ 1 : {
6+ "title" : "Add new customer details" ,
7+ "method" : lambda : add ()
8+ },
9+
10+ 2 : {
11+ "title" : "Modify already existing customer details" ,
12+ "method" : lambda : modify ()
13+ },
14+
15+ 3 : {
16+ "title" : "Search customer details" ,
17+ "method" : lambda : search ()
18+ },
19+
20+ 4 : {
21+ "title" : "View all customer details" ,
22+ "method" : lambda : view ()
23+ },
24+
25+ 5 : {
26+ "title" : "Delete customer details" ,
27+ "method" : lambda : remove ()
28+ },
29+
30+ 6 : {
31+ "title" : "Exit the program" ,
32+ "method" : lambda : exit ()
33+ }
34+ }
2635
27- elif user_input == 4 :
28- view ()
36+ print (f"\n \n { ' ' * 25 } Welcome to Hotel Database Management Software\n \n " )
2937
30- elif user_input == 5 :
31- remove ()
38+ for num , option in options .items ():
39+ print (f"{ num } : { option .get ('title' )} " )
40+ print ()
3241
33- elif user_input == 6 :
34- exit ()
42+ options .get ( int (input ("Enter your choice(1-6): " )) ).get ("method" )()
3543
3644
3745def add ():
3846
39- print ("" )
40- Name1 = input ("Enter your first name: " )
41- print ("" )
42-
43- Name2 = input ("Enter your last name: " )
44- print ("" )
45-
46- Phone_Num = input ("Enter your phone number(without +91): " )
47- print ("" )
47+ Name1 = input ("\n Enter your first name: \n " )
48+ Name2 = input ("\n Enter your last name: \n " )
49+ Phone_Num = input ("\n Enter your phone number(without +91): \n " )
4850
4951 print ("These are the rooms that are currently available" )
5052 print ("1-Normal (500/Day)" )
5153 print ("2-Deluxe (1000/Day)" )
5254 print ("3-Super Deluxe (1500/Day)" )
5355 print ("4-Premium Deluxe (2000/Day)" )
54- print ("" )
55- Room_Type = int (input ("Which type you want(1-4): " ))
56- print ("" )
5756
58- if Room_Type == 1 :
59- x = 500
60- Room_Type = "Normal"
61- elif Room_Type == 2 :
62- x = 1000
63- Room_Type = "Deluxe"
64- elif Room_Type == 3 :
65- x = 1500
66- Room_Type = "Super Deluxe"
67- elif Room_Type == 4 :
68- x = 2000
69- Room_Type = "Premium"
57+ Room_Type = int (input ("\n Which type you want(1-4): \n " ))
58+
59+ match Room_Type :
60+ case 1 :
61+ x = 500
62+ Room_Type = "Normal"
63+ case 2 :
64+ x = 1000
65+ Room_Type = "Deluxe"
66+ case 3 :
67+ x = 1500
68+ Room_Type = "Super Deluxe"
69+ case 4 :
70+ x = 2000
71+ Room_Type = "Premium"
7072
7173 Days = int (input ("How many days you will stay: " ))
7274 Money = x * Days
@@ -85,11 +87,10 @@ def add():
8587 print ("Online payment" )
8688 print ("" )
8789
88- File = open ("Management.txt" , "r" )
89- string = File .read ()
90- string = string .replace ("'" , '"' )
91- dictionary = json .loads (string )
92- File .close ()
90+ with open ("Management.txt" , "r" ) as File :
91+ string = File .read ()
92+ string = string .replace ("'" , '"' )
93+ dictionary = json .loads (string )
9394
9495 if len (dictionary .get ("Room" )) == 0 :
9596 Room_num = "501"
@@ -114,12 +115,10 @@ def add():
114115 dictionary ["Price" ].append (Money )
115116 dictionary ["Room" ].append (Room_num )
116117
117- File = open ("Management.txt" , "w" , encoding = "utf-8" )
118- File .write (str (dictionary ))
119- File .close ()
118+ with open ("Management.txt" , "w" , encoding = "utf-8" ) as File :
119+ File .write (str (dictionary ))
120120
121- print ("" )
122- print ("Your data has been successfully added to our database." )
121+ print ("\n Your data has been successfully added to our database." )
123122
124123 exit_menu ()
125124
@@ -128,148 +127,113 @@ def add():
128127import json
129128
130129filecheck = os .path .isfile ("Management.txt" )
131- if filecheck == False :
132- File = open ("Management.txt" , "a" , encoding = "utf-8" )
133- temp1 = {
134- "First_Name" : [],
135- "Last_Name" : [],
136- "Phone_num" : [],
137- "Room_Type" : [],
138- "Days" : [],
139- "Price" : [],
140- "Room" : [],
141- }
142- File .write (str (temp1 ))
143- File .close ()
130+ if not filecheck :
131+ with open ("Management.txt" , "a" , encoding = "utf-8" ) as File :
132+ temp1 = {
133+ "First_Name" : [],
134+ "Last_Name" : [],
135+ "Phone_num" : [],
136+ "Room_Type" : [],
137+ "Days" : [],
138+ "Price" : [],
139+ "Room" : [],
140+ }
141+ File .write (str (temp1 ))
144142
145143
146144def modify ():
147145
148- File = open ("Management.txt" , "r" )
149- string = File .read ()
150- string = string .replace ("'" , '"' )
151- dictionary = json .loads (string )
152- File .close ()
146+ with open ("Management.txt" , "r" ) as File :
147+ string = File .read ()
148+ string = string .replace ("'" , '"' )
149+ dictionary = json .loads (string )
153150
154151 dict_num = dictionary .get ("Room" )
155152 dict_len = len (dict_num )
156153 if dict_len == 0 :
157- print ("" )
158- print ("There is no data in our database" )
159- print ("" )
154+ print ("\n There is no data in our database\n " )
160155 menu ()
161156 else :
162- print ("" )
163- Room = input ("Enter your Room Number: " )
157+ Room = input ("\n Enter your Room Number: " )
164158
165159 listt = dictionary ["Room" ]
166160 index = int (listt .index (Room ))
167161
168- print ("" )
169- print ("1-Change your first name" )
162+ print ("\n 1-Change your first name" )
170163 print ("2-Change your last name" )
171164 print ("3-Change your phone number" )
172165
173- print ("" )
174- choice = input ("Enter your choice: " )
175- print ("" )
176-
177- File = open ("Management.txt" , "w" , encoding = "utf-8" )
178-
179- if choice == str (1 ):
180- user_input = input ("Enter New First Name: " )
181- listt1 = dictionary ["First_Name" ]
166+ choice = int (input ("\n Enter your choice: " ))
167+ print ()
168+
169+ with open ("Management.txt" , "w" , encoding = "utf-8" ) as File :
170+
171+ match choice :
172+ case 1 :
173+ category = "First_Name"
174+ case 2 :
175+ category = "Last_Name"
176+ case 3 :
177+ category = "Phone_num"
178+
179+ user_input = input (f"Enter New { category .replace ('_' , ' ' )} " )
180+ listt1 = dictionary [category ]
182181 listt1 [index ] = user_input
183- dictionary ["First_Name" ] = None
184- dictionary ["First_Name" ] = listt1
185- File .write (str (dictionary ))
186- File .close ()
182+ dictionary [category ] = None
183+ dictionary [category ] = listt1
187184
188- elif choice == str (2 ):
189- user_input = input ("Enter New Last Name: " )
190- listt1 = dictionary ["Last_Name" ]
191- listt1 [index ] = user_input
192- dictionary ["Last_Name" ] = None
193- dictionary ["Last_Name" ] = listt1
194185 File .write (str (dictionary ))
195- File .close ()
196-
197- elif choice == str (3 ):
198- user_input = input ("Enter New Phone Number: " )
199- listt1 = dictionary ["Phone_num" ]
200- listt1 [index ] = user_input
201- dictionary ["Phone_num" ] = None
202- dictionary ["Phone_num" ] = listt1
203- File .write (str (dictionary ))
204- File .close ()
205-
206- print ("" )
207- print ("Your data has been successfully updated" )
208186
187+ print ("\n Your data has been successfully updated" )
209188 exit_menu ()
210189
211190
212191def search ():
213192
214- File = open ("Management.txt" , "r" )
215- string = File .read ()
216- string = string .replace ("'" , '"' )
217- dictionary = json .loads (string )
218- File .close ()
193+ with open ("Management.txt" ) as File :
194+ dictionary = json .loads (File .read ().replace ("'" , '"' ))
219195
220196 dict_num = dictionary .get ("Room" )
221197 dict_len = len (dict_num )
198+
222199 if dict_len == 0 :
223- print ("" )
224- print ("There is no data in our database" )
225- print ("" )
200+ print ("\n There is no data in our database\n " )
226201 menu ()
227202 else :
228- print ("" )
229- Room = input ("Enter your Room Number: " )
230- print ("" )
203+ Room = input ("\n Enter your Room Number: " )
231204
232- listt = dictionary [ "Room" ]
233- index = int (listt .index (Room ))
205+ listt_num = dictionary . get ( "Room" )
206+ index = int (listt_num .index (Room ))
234207
235208 listt_fname = dictionary .get ("First_Name" )
236209 listt_lname = dictionary .get ("Last_Name" )
237210 listt_phone = dictionary .get ("Phone_num" )
238211 listt_type = dictionary .get ("Room_Type" )
239212 listt_days = dictionary .get ("Days" )
240213 listt_price = dictionary .get ("Price" )
241- listt_num = dictionary .get ("Room" )
242214
243- print ("" )
244- print ("First Name:" , listt_fname [index ])
245- print ("Last Name:" , listt_lname [index ])
246- print ("Phone number:" , listt_phone [index ])
247- print ("Room Type:" , listt_type [index ])
248- print ("Days staying:" , listt_days [index ])
249- print ("Money paid:" , listt_price [index ])
250- print ("Room Number:" , listt_num [index ])
215+ print (f"\n First Name: { listt_fname [index ]} " )
216+ print (f"Last Name: { listt_lname [index ]} " )
217+ print (f"Phone number: { listt_phone [index ]} " )
218+ print (f"Room Type: { listt_type [index ]} " )
219+ print (f"Days staying: { listt_days [index ]} " )
220+ print (f"Money paid: { listt_price [index ]} " )
221+ print (f"Room Number: { listt_num [index ]} " )
251222
252223 exit_menu ()
253224
254225
255226def remove ():
256- File = open ("Management.txt" , "r" )
257- string = File .read ()
258- string = string .replace ("'" , '"' )
259- dictionary = json .loads (string )
260- File .close ()
227+ with open ("Management.txt" ) as File :
228+ dictionary = json .loads (File .read ().replace ("'" , '"' ))
261229
262230 dict_num = dictionary .get ("Room" )
263231 dict_len = len (dict_num )
264232 if dict_len == 0 :
265- print ("" )
266- print ("There is no data in our database" )
267- print ("" )
233+ print ("\n There is no data in our database\n " )
268234 menu ()
269235 else :
270- print ("" )
271- Room = input ("Enter your Room Number: " )
272- print ("" )
236+ Room = input ("\n Enter your Room Number: " )
273237
274238 listt = dictionary ["Room" ]
275239 index = int (listt .index (Room ))
@@ -311,9 +275,8 @@ def remove():
311275 dictionary ["Room" ] = None
312276 dictionary ["Room" ] = listt_num
313277
314- file1 = open ("Management.txt" , "w" , encoding = "utf-8" )
315- file1 .write (str (dictionary ))
316- file1 .close ()
278+ with open ("Management.txt" , "w" , encoding = "utf-8" ) as file1 :
279+ file1 .write (str (dictionary ))
317280
318281 print ("Details has been removed successfully" )
319282
@@ -322,18 +285,13 @@ def remove():
322285
323286def view ():
324287
325- File = open ("Management.txt" , "r" )
326- string = File .read ()
327- string = string .replace ("'" , '"' )
328- dictionary = json .loads (string )
329- File .close ()
288+ with open ("Management.txt" ) as File :
289+ dictionary = json .loads (File .read ().replace ("'" , '"' ))
330290
331291 dict_num = dictionary .get ("Room" )
332292 dict_len = len (dict_num )
333293 if dict_len == 0 :
334- print ("" )
335- print ("There is no data in our database" )
336- print ("" )
294+ print ("\n There is no data in our database\n " )
337295 menu ()
338296
339297 else :
0 commit comments