-
Notifications
You must be signed in to change notification settings - Fork 2
/
basic_crud.py
72 lines (55 loc) · 1.77 KB
/
basic_crud.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
#!/usr/bin/python3
"""
Simple Python script with CRUD operations on a list
"""
clients = []
def create_client(client_name):
clients.append(client_name)
print('Created')
def update_client(client_name, new_name):
found_index = find_client_index(client_name)
if found_index != None:
print(f'Found {clients[found_index]} at {found_index}. Modifying...')
clients[found_index] = new_name
print('Modified.')
else:
print(f'{client_name} not found')
def delete_client(client_name):
found_index = find_client_index(client_name)
if found_index != None:
del clients[found_index]
print('Deleted')
else:
print(f'{client_name} not found')
def find_client_index(client_name):
return next((i for i, x in enumerate(clients) if x == client_name), None)
def list_clients():
print(clients)
def print_welcome():
print('WELCOME TO THE SALES SYSTEM')
print('*' * 50)
print('What would you like to do?')
print('[C]reate')
print('[L]ist')
print('[U]pdate')
print('[D]elete')
print('E[x]it')
if __name__ == '__main__':
finished = False
while not finished:
print_welcome()
option = input().upper()
if option == 'C':
create_client(input('Enter the name of the client: '))
elif option == 'L':
list_clients()
elif option == 'X':
finished = True
elif option == 'U':
search_client = input('Enter the name of the client to modify: ')
new_client = input('Enter the new name: ')
update_client(search_client, new_client)
elif option == 'D':
delete_client(input('Enter the name of the client to delete: '))
else:
print('Invalid option')