MCPcopy Create free account
hub / github.com/geekcomputers/Python / modify

Function modify

Hotel-Management.py:121–163  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

119
120
121def modify():
122 with open("Management.txt", "r") as File:
123 string = File.read()
124 string = string.replace("'", '"')
125 dictionary = json.loads(string)
126
127 dict_num = dictionary.get("Room")
128 dict_len = len(dict_num)
129 if dict_len == 0:
130 print("\nThere is no data in our database\n")
131 menu()
132 else:
133 Room = input("\nEnter your Room Number: ")
134
135 listt = dictionary["Room"]
136 index = int(listt.index(Room))
137
138 print("\n1-Change your first name")
139 print("2-Change your last name")
140 print("3-Change your phone number")
141
142 choice = int(input("\nEnter your choice: "))
143 print()
144
145 with open("Management.txt", "w", encoding="utf-8") as File:
146 match choice:
147 case 1:
148 category = "First_Name"
149 case 2:
150 category = "Last_Name"
151 case 3:
152 category = "Phone_num"
153
154 user_input = input(f"Enter New {category.replace('_', ' ')}")
155 listt1 = dictionary[category]
156 listt1[index] = user_input
157 dictionary[category] = None
158 dictionary[category] = listt1
159
160 File.write(str(dictionary))
161
162 print("\nYour data has been successfully updated")
163 exit_menu()
164
165
166def search():

Callers 1

menuFunction · 0.85

Calls 4

menuFunction · 0.85
exit_menuFunction · 0.85
getMethod · 0.45
indexMethod · 0.45

Tested by

no test coverage detected