Este es el código en cuestión:
import sys
clients = ['luisa', 'juan']
def create_client(client_name):
global clients
if client_name not in clients :
clients.append(client_name)
else:
print ('Client already is in the client\'s list')
def list_clients():
for idx, client in enumerate(clients):
print ('{} : {}'.format(idx, client))
def updated_client(client_name, updated_client_name):
global clients
if client_name in clients :
index = clients.index(client_name)
clients[index] = updated_name
else:
print ('Client is no it client\'s list')
def delete_client(client_name):
global clients
if client_name in clients:
clients.remove(client_name)
else:
print('Client is not in client\'s 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 you like to do today ? ')
print ('[C]reate client')
print ('[L]ist client')
print ('[U]pdated client')
print ('[D]elete client')
print ('[S]earch client')
def _get_client_name ():
client_name = None
while not client_name:
client_name = str.lower(input('What is the client name ? '))
if client_name == 'exit':
client_name = None
break
if not client_name:
sys.exit()
return client_name
if __name__ == '__main__':
_print_welcome()
command = input('Select option')
command = command.upper()
if command == 'C':
client_name = _get_client_name()
create_client(client_name)
list_clients()
elif command == 'L':
list_clients()
elif command == 'U':
client_name = _get_client_name()
updated_name = str.lower(input ('What is the updated client name ? '))
updated_client(client_name, updated_name)
list_clients()
elif command == 'D':
client_name = _get_client_name()
delete_client(client_name)
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 our client\'s list'.format(client_name))
else:
print ('Invalid command')
Y al ejecutarlo. Este es el error que me da:
WELCOME TO PLATZI VENTAS
**************************************************
What would you like to do today ?
[C]reate client
[L]ist client
[U]pdated client
[D]elete client
[S]earch client
Select optionC
Traceback (most recent call last):
File "main.py", line 74, in <module>
command = input('Select option')
File "<string>", line 1, in <module>
NameError: name 'C' is not defined
Sin embargo si en lugar de añadir una solamente la letra pongo la letra + comillas. Sí que me reconoce la letra:
WELCOME TO PLATZI VENTAS
**************************************************
What would you like to do today ?
[C]reate client
[L]ist client
[U]pdated client
[D]elete client
[S]earch client
Select option'C'
What is the client name ?
Lo mismo me pasa con todos los demás inputs del programa. No sé si es un problema a la hora de declarar el input que debo especificar que es un String. Aunque según he leído esto debería hacerlo ya por defecto.
O es un problema a la hora de hacer las declaraciones de los if, elif y else. Que no reconocen el String o que al comparar debo especificar que el elemento con el que lo estoy comparando es un String.
Ayuda URGENTE please!!