Mi versión del código
import sys
clients = [
{
'name': 'Pablo',
'company': 'Google',
'email': '[email protected]',
'position': 'Sofware Engineer',
},
{
'name': 'Ricardo',
'company': 'Facebook',
'email': '[email protected]',
'position': 'Data Engineer',
},
]
def create_client(client):
global clients
if client not in clients:
clients.append(client)
else:
print('Client already is in client\'s list')
def list_clients():
for idx, client in enumerate(clients):
print('{uid} | {name} | {company} | {email} | {position}'.format(
uid = idx,
name = client['name'],
company = client['company'],
email = client['email'],
position = client['position']))
def ingress_client_data():
client = {
'name': _get_client_field('name'),
'company': _get_client_field('company'),
'email': _get_client_field('email'),
'position': _get_client_field('position')
}
return client
def update_client(client_id, updated_client):
global clients
if len(clients) -1 >= client_id:
clients[client_id] = updated_client
else:
print('Client is not in clients list')
def delete_client(client_name):
global clients
if client_name in clients:
clients.remove(client_name)
else:
print('Client is not in clients list')
def search_client(client_name):
for client in clients:
if client != client_name:
continue
else:
return True
def _print_welcome():
print('WELCOME TO PLATZI VENTAS')
print('*' * 50)
print('What would yo like to do today?')
print('[C]reated client')
print('[U]pdate client')
print('[L]ist clients')
print('[D]elete client')
print('[S]earch client')
def _get_client_field(field_name):
field = None
while not field:
field = input('What is the client {}? '.format(field_name))
return field
if __name__ == '__main__':
_print_welcome()
command = input()
command = command.upper()
if command == 'C':
client = ingress_client_data()
create_client(client)
list_clients()
elif command == 'D':
client_name = _get_client_name()
delete_client(client_name)
list_clients()
elif command == 'U':
list_clients()
client_id = int(_get_client_field('id'))
updated_client = ingress_client_data()
update_client(client_id, updated_client)
list_clients()
elif command == 'L':
list_clients()
elif command == 'S':
client_name = _get_client_name()
found = search_client(client_name)
if found:
print('The client is in the client\'s list')
else :
print('The client: {} is not in client\'s list'.format(client_name))
else:
print('Invalid command')
¿Quieres ver más aportes, preguntas y respuestas de la comunidad?