Skip to content

Code Factorization and performance enhancements #1947

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
286 changes: 122 additions & 164 deletions Hotel-Management.py
Original file line number Diff line number Diff line change
@@ -1,72 +1,74 @@
def menu():
print("")
print("")
print(" Welcome to Hotel Database Management Software")
print("")
print("")

print("1-Add new customer details")
print("2-Modify already existing customer details")
print("3-Search customer details")
print("4-View all customer details")
print("5-Delete customer details")
print("6-Exit the program")
print("")

user_input = int(input("Enter your choice(1-6): "))

if user_input == 1:
add()

elif user_input == 2:
modify()
def menu():

elif user_input == 3:
search()
options = {
1 : {
"title" : "Add new customer details",
"method": lambda : add()
},

2 : {
"title" : "Modify already existing customer details",
"method": lambda : modify()
},

3 : {
"title" : "Search customer details",
"method": lambda : search()
},

4 : {
"title" : "View all customer details",
"method": lambda : view()
},

5 : {
"title" : "Delete customer details",
"method": lambda : remove()
},

6 : {
"title" : "Exit the program",
"method": lambda : exit()
}
}

elif user_input == 4:
view()
print(f"\n\n{' '*25}Welcome to Hotel Database Management Software\n\n")

elif user_input == 5:
remove()
for num, option in options.items():
print(f"{num}: {option.get('title')}")
print()

elif user_input == 6:
exit()
options.get( int(input("Enter your choice(1-6): ")) ).get("method")()


def add():

print("")
Name1 = input("Enter your first name: ")
print("")

Name2 = input("Enter your last name: ")
print("")

Phone_Num = input("Enter your phone number(without +91): ")
print("")
Name1 = input("\nEnter your first name: \n")
Name2 = input("\nEnter your last name: \n")
Phone_Num = input("\nEnter your phone number(without +91): \n")

print("These are the rooms that are currently available")
print("1-Normal (500/Day)")
print("2-Deluxe (1000/Day)")
print("3-Super Deluxe (1500/Day)")
print("4-Premium Deluxe (2000/Day)")
print("")
Room_Type = int(input("Which type you want(1-4): "))
print("")

if Room_Type == 1:
x = 500
Room_Type = "Normal"
elif Room_Type == 2:
x = 1000
Room_Type = "Deluxe"
elif Room_Type == 3:
x = 1500
Room_Type = "Super Deluxe"
elif Room_Type == 4:
x = 2000
Room_Type = "Premium"
Room_Type = int(input("\nWhich type you want(1-4): \n"))

match Room_Type:
case 1:
x = 500
Room_Type = "Normal"
case 2:
x = 1000
Room_Type = "Deluxe"
case 3:
x = 1500
Room_Type = "Super Deluxe"
case 4:
x = 2000
Room_Type = "Premium"

Days = int(input("How many days you will stay: "))
Money = x * Days
Expand All @@ -85,11 +87,10 @@ def add():
print("Online payment")
print("")

File = open("Management.txt", "r")
string = File.read()
string = string.replace("'", '"')
dictionary = json.loads(string)
File.close()
with open("Management.txt", "r") as File:
string = File.read()
string = string.replace("'", '"')
dictionary = json.loads(string)

if len(dictionary.get("Room")) == 0:
Room_num = "501"
Expand All @@ -114,12 +115,10 @@ def add():
dictionary["Price"].append(Money)
dictionary["Room"].append(Room_num)

File = open("Management.txt", "w", encoding="utf-8")
File.write(str(dictionary))
File.close()
with open("Management.txt", "w", encoding="utf-8") as File:
File.write(str(dictionary))

print("")
print("Your data has been successfully added to our database.")
print("\nYour data has been successfully added to our database.")

exit_menu()

Expand All @@ -128,148 +127,113 @@ def add():
import json

filecheck = os.path.isfile("Management.txt")
if filecheck == False:
File = open("Management.txt", "a", encoding="utf-8")
temp1 = {
"First_Name": [],
"Last_Name": [],
"Phone_num": [],
"Room_Type": [],
"Days": [],
"Price": [],
"Room": [],
}
File.write(str(temp1))
File.close()
if not filecheck:
with open("Management.txt", "a", encoding="utf-8") as File:
temp1 = {
"First_Name": [],
"Last_Name": [],
"Phone_num": [],
"Room_Type": [],
"Days": [],
"Price": [],
"Room": [],
}
File.write(str(temp1))


def modify():

File = open("Management.txt", "r")
string = File.read()
string = string.replace("'", '"')
dictionary = json.loads(string)
File.close()
with open("Management.txt", "r") as File:
string = File.read()
string = string.replace("'", '"')
dictionary = json.loads(string)

dict_num = dictionary.get("Room")
dict_len = len(dict_num)
if dict_len == 0:
print("")
print("There is no data in our database")
print("")
print("\nThere is no data in our database\n")
menu()
else:
print("")
Room = input("Enter your Room Number: ")
Room = input("\nEnter your Room Number: ")

listt = dictionary["Room"]
index = int(listt.index(Room))

print("")
print("1-Change your first name")
print("\n1-Change your first name")
print("2-Change your last name")
print("3-Change your phone number")

print("")
choice = input("Enter your choice: ")
print("")

File = open("Management.txt", "w", encoding="utf-8")

if choice == str(1):
user_input = input("Enter New First Name: ")
listt1 = dictionary["First_Name"]
choice = int(input("\nEnter your choice: "))
print()

with open("Management.txt", "w", encoding="utf-8") as File:

match choice:
case 1:
category = "First_Name"
case 2:
category = "Last_Name"
case 3:
category = "Phone_num"

user_input = input(f"Enter New {category.replace('_', ' ')}")
listt1 = dictionary[category]
listt1[index] = user_input
dictionary["First_Name"] = None
dictionary["First_Name"] = listt1
File.write(str(dictionary))
File.close()
dictionary[category] = None
dictionary[category] = listt1

elif choice == str(2):
user_input = input("Enter New Last Name: ")
listt1 = dictionary["Last_Name"]
listt1[index] = user_input
dictionary["Last_Name"] = None
dictionary["Last_Name"] = listt1
File.write(str(dictionary))
File.close()

elif choice == str(3):
user_input = input("Enter New Phone Number: ")
listt1 = dictionary["Phone_num"]
listt1[index] = user_input
dictionary["Phone_num"] = None
dictionary["Phone_num"] = listt1
File.write(str(dictionary))
File.close()

print("")
print("Your data has been successfully updated")

print("\nYour data has been successfully updated")
exit_menu()


def search():

File = open("Management.txt", "r")
string = File.read()
string = string.replace("'", '"')
dictionary = json.loads(string)
File.close()
with open("Management.txt") as File:
dictionary = json.loads(File.read().replace("'", '"'))

dict_num = dictionary.get("Room")
dict_len = len(dict_num)

if dict_len == 0:
print("")
print("There is no data in our database")
print("")
print("\nThere is no data in our database\n")
menu()
else:
print("")
Room = input("Enter your Room Number: ")
print("")
Room = input("\nEnter your Room Number: ")

listt = dictionary["Room"]
index = int(listt.index(Room))
listt_num = dictionary.get("Room")
index = int(listt_num.index(Room))

listt_fname = dictionary.get("First_Name")
listt_lname = dictionary.get("Last_Name")
listt_phone = dictionary.get("Phone_num")
listt_type = dictionary.get("Room_Type")
listt_days = dictionary.get("Days")
listt_price = dictionary.get("Price")
listt_num = dictionary.get("Room")

print("")
print("First Name:", listt_fname[index])
print("Last Name:", listt_lname[index])
print("Phone number:", listt_phone[index])
print("Room Type:", listt_type[index])
print("Days staying:", listt_days[index])
print("Money paid:", listt_price[index])
print("Room Number:", listt_num[index])
print(f"\nFirst Name: {listt_fname[index]}")
print(f"Last Name: {listt_lname[index]}")
print(f"Phone number: {listt_phone[index]}")
print(f"Room Type: {listt_type[index]}")
print(f"Days staying: {listt_days[index]}")
print(f"Money paid: {listt_price[index]}")
print(f"Room Number: {listt_num[index]}")

exit_menu()


def remove():
File = open("Management.txt", "r")
string = File.read()
string = string.replace("'", '"')
dictionary = json.loads(string)
File.close()
with open("Management.txt") as File:
dictionary = json.loads(File.read().replace("'", '"'))

dict_num = dictionary.get("Room")
dict_len = len(dict_num)
if dict_len == 0:
print("")
print("There is no data in our database")
print("")
print("\nThere is no data in our database\n")
menu()
else:
print("")
Room = input("Enter your Room Number: ")
print("")
Room = input("\nEnter your Room Number: ")

listt = dictionary["Room"]
index = int(listt.index(Room))
Expand Down Expand Up @@ -311,9 +275,8 @@ def remove():
dictionary["Room"] = None
dictionary["Room"] = listt_num

file1 = open("Management.txt", "w", encoding="utf-8")
file1.write(str(dictionary))
file1.close()
with open("Management.txt", "w", encoding="utf-8") as file1:
file1.write(str(dictionary))

print("Details has been removed successfully")

Expand All @@ -322,18 +285,13 @@ def remove():

def view():

File = open("Management.txt", "r")
string = File.read()
string = string.replace("'", '"')
dictionary = json.loads(string)
File.close()
with open("Management.txt") as File:
dictionary = json.loads(File.read().replace("'", '"'))

dict_num = dictionary.get("Room")
dict_len = len(dict_num)
if dict_len == 0:
print("")
print("There is no data in our database")
print("")
print("\nThere is no data in our database\n")
menu()

else:
Expand Down
Loading