-
Notifications
You must be signed in to change notification settings - Fork 37
/
user_management_system.py
133 lines (121 loc) · 4.28 KB
/
user_management_system.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
database = {'entries': []}
SRNO = 'srno'
NAME = 'name'
AGE = 'age'
GENDER = 'gender'
OCCUPATION = 'occupation'
def get_serial_no():
return len(database['entries']) + 1
def add_entry(entry):
entry = {
'srno': get_serial_no(),
'name': entry['name'],
'age': entry['age'],
'gender': entry['gender'],
'occupation': entry['occupation']
}
database['entries'].append(entry)
def check_entry_presence(value):
for num, entry in enumerate(database['entries']):
if entry[value[0]] == value[1]:
return 1
return 0
def search_entry(value):
for num, entry in enumerate(database['entries']):
if entry[value[0]] == value[1]:
return entry
def update_entry(value, updated_entry):
for num, entry in enumerate(database['entries']):
if entry[value[0]] == value[1]:
database['entries'][num] == updated_entry
def delete_entry(value):
for num, entry in enumerate(database['entries']):
if entry[value[0]] == value[1]:
database['entries'].remove(entry)
def display_entry(entry):
print(f"SRNO: {entry['srno']}")
print(f"Name: {entry['name']}")
print(f"Age: {entry['age']}")
print(f"Gender: {entry['gender']}")
print(f"Occupation: {entry['occupation']}\n")
def display_all_entries():
for entry in database["entries"]:
display_entry(entry)
def select_entry_and_value():
value_type = ''
value = ''
while 1:
print('Choose an entry based on which to search entries in database: ')
print("1. srno")
print("2. name")
print("3. age")
print("4. gender")
print("5. occupation")
choice = int(input("Enter your choice: "))
if choice < 1 or choice > 5:
print("Invalid input...please try again")
else:
if choice == 1:
value_type = SRNO
value = input("Enter serial number to search: ")
return (value_type, value)
elif choice == 2:
value_type = NAME
value = input("Enter name to search: ")
return (value_type, value)
elif choice == 3:
value_type = AGE
value = input("Enter age to search: ")
return (value_type, value)
elif choice == 4:
value_type = GENDER
value = input("Enter gender to search: ")
return (value_type, value)
elif choice == 5:
value_type = OCCUPATION
value = input("Enter occupation to search: ")
return (value_type, value)
def get_entry_details():
output = {}
output[NAME] = input("Enter name: ")
output[AGE] = input("Enter age: ")
output[GENDER] = input("Enter gender: ")
output[OCCUPATION] = input("Enter occupation: ")
return output
print("===== Welcome To User Management System =====")
while 1:
print("\nWhat would you like to do:-")
print("1. Add an entry")
print("2. Update an entry")
print("3. Delete an entry")
print("4. Search an entry")
print("5. Display all entries")
print("6. Exit")
choice = int(input("Enter your choice: "))
if choice > 7 or choice < 1:
print("Invalid input...please try again")
else:
if choice == 1:
print("Enter details for the new entry:-")
entry = get_entry_details()
add_entry(entry)
print("Entry successfully created...")
elif choice == 2:
value = select_entry_and_value()
print('Enter the details of the updated entry:-')
entry = get_entry_details()
update_entry(value, entry)
print("Entry successfully updated...")
elif choice == 3:
value = select_entry_and_value()
delete_entry(value)
print("Entry successfully deleted...")
elif choice == 4:
value = select_entry_and_value()
entry = search_entry(value)
display_entry(entry)
elif choice == 5:
display_all_entries()
elif choice == 6:
print('Exiting')
break