def new_booking(): global s, p, d ch_typ = {'s':s, 'p':p, 'd':d} # dictionary of choice (got below), and room type if all(len(i) != 0 for i in ch_typ.values()): print("Enter Info for a New Booking. Press Enter anytime to exit.") print("What type of room you want to book?\n\t[magenta]⟪S⟫ Standard Room\n\t⟪D⟫ Deluxe Room\n\t⟪P⟫ Premium Room[/magenta]") while True: try: ch = input("Enter your choice(S, P, D): ").lower() if ch not in ch_typ.keys(): if ch == '': return else: raise ValueError break except ValueError: print("[red]Pls Enter a Valid Choice.[/red]") typ = ch_typ[ch] r = list(typ)[0] typ.remove(r) nam = input("Enter GUEST NAME:") if nam == '': return phone = phone_input() # a function called if phone == '': return print("[cyan]Room Booked![/cyan]") while True: print("Your details:") print(f"\tRoom no: [magenta]{r}[magenta]") print(f"\tName: [magenta]{nam}[/magenta]") print(f"\tPhone number: [magenta]{phone}[/magenta]") ask = input("Want to change anything? Enter y for yes and n for no\n").lower() if ask == 'y': try: f = update_guest("ch") if type(f) != tuple: raise MyTypeError else: r, nam, phone = f except MyTypeError: pass else: cursor.execute("select room_key from hotel_rooms where roomno={}".format(r)) k = cursor.fetchone() key = k[0] cursor.execute(f"update hotel_rooms set guestname='{nam}', phone='{phone}' where roomno={r}") print(f"[magenta][cyan]Okay! Here's your key:[/cyan] {key}[/magenta]") cnx.commit() break else: print("[cyan]Sorry, Housefull.😥[/cyan]") if input("Press Enter to continue.") == '': return def update_guest(a): ''' This function takes 1 argument ("ch" or "up"). if "ch" is given, a guest recheck is done. Otherwise simple update. ''' if a == "up": print("Enter Room No to Update Info. Press Enter anytime to exit.") r = get_room_input() if r == '': return if r < 51: typ = s elif r < 76: typ = d else: typ = p if r not in typ: cursor.execute("select roomno, guestname, phone, class from hotel_rooms where roomno={}".format(r)) data = cursor.fetchone() room, nam, phone, clss = data print(f"Old Info:-\n\t[magenta]Room no: {room}\n\tGuest Name: {nam}\n\tPhone no: {phone}\n\tType of Room: {clss}[/magenta]") print("Enter New Info") print("Enter New ROOM NO", end='') n = get_room_input() if n == '': return elif (n in i for i in (s, p, d)): print("Room already occcupied.") nam = input("Enter GUEST NAME:") if nam == '': return phone = phone_input() if phone == '': return while True: k = input("Enter six-digit-key: ") cursor.execute(f"select room_key from hotel_rooms where roomno={r}") data = cursor.fetchone() if k == data[0]: cursor.execute(f"update hotel_rooms set guestname='{nam}', phone='{phone}' where roomno={r}") cnx.commit() print("Room Updated.") break elif k == '': print("Updation cancelled.") time.sleep(1) return else: print("[red]Incorrect key.[/red]") else: print("Room no. {} is unoccupied.".format(r)) if input("Press Enter to continue.") == '': return elif a == "ch": print("Enter New Values to change. Press Enter anytime to exit.") print("Enter New ROOM NO", end='') n = get_room_input() if n == '': return r = change_room(r, n) nam = input("Enter Name:") if nam == '': return phone = phone_input() if phone == '': return return r, nam, phone def change_room(old_r, new_r): o = old_r n = new_r cursor.execute("select guestname, phone from hotel_rooms where roomno={}".format(o)) data = cursor.fetchone() nam, phone = data cursor.execute("update hotel_rooms set guestname=NULL, phone=NULL where roomno={}".format(o)) cnx.commit() cursor.execute("update hotel_rooms set guestname={}, phone={} where roomno={}".format(nam, phone, n)) cnx.commit() return n