Hola alguien puede ayudarme con este error? <code>Traceback (most recent call last): File "main.py", line 60, in &lt;module&gt; com...

Samuel Paredes

Samuel Paredes

Pregunta
studenthace 7 años

Hola alguien puede ayudarme con este error?

Traceback (most recent call last): File "main.py", line 60, in <module> command = input() File "<string>", line 1, in <module> NameError: name 'U' is not defined```
5 respuestas
para escribir tu comentario
    Samuel Paredes

    Samuel Paredes

    studenthace 7 años

    Gracias Dane, me sirvo mucho checar lo que me recomendaste.

    Danelia Sanchez Sanchez

    Danelia Sanchez Sanchez

    studenthace 7 años

    Hola @samuelparedes001, revisando tu código no veo detalle alguno. ¿Estás usando python 2.x? Si es así, no puedes usar la función input() ya que pertenece a python 3 y versiones posteriores. Para ello, usa la función raw_input() o instala la última versión. Saludos.

    Samuel Paredes

    Samuel Paredes

    studenthace 7 años

    Aqui tengo otra version de mi código tratando de seguir detalladamente al profesor.

    1 2 3 clients = 'pablo, ricardo, ' 4 5 def create_client(client_name): 6 global clients 7 8 if client_name not in clients: 9 clients += client_name 10 _add_comma() 11 12 else: 13 print('Client already is in the client\'s list') 14 15 16 def list_clients(): 17 global clients 18 19 print(clients) 20 21 22 def update_client(client_name, updated_client_name): 23 global clients 24 25 if client_name in clients: 26 clients = clients.replace(client_name + ',' , updated_client_name + ',') 27 else: 28 print('Client is not in clients list') 29 30 def _add_comma(): 31 global clients 32 33 clients += ',' 34 35 36 def _print_welcome(): 37 print('WELCOME TO PLATZI VENTAS') 38 print('*' * 50) 39 print('What would you like to do?') 40 print('[C]reate client') 41 print('[U]pdated client') 42 print('[D]elete client') 43 44 45 def _get_client_name(): 46 return input('What is the client name?') 47 48 49 if __name__ == '__main__': 50 _print_welcome() 51 52 command = input() 53 command = command.upper() 54 55 if command == 'C': 56 client_name = _get_client_name() 57 create_client(client_name) 58 list_clients() 59 elif command == 'D': 60 pass 61 elif command == 'U': 62 client_name = _get_client_name() 63 updated_client_name = input('What is the updated client name?') 64 update_client(client_name, updated_client_name) 65 list_clients() 66 else: 67 print('invalid command') 68```
    Samuel Paredes

    Samuel Paredes

    studenthace 7 años

    mi codigo es:

    clients = 'pablo,ricardo,' def create_client(client_name): global clients if client_name not in clients: clients += client_name _add_comma() else: print('Client already in client\'s list') def list_clients(): print(clients) def update_client(client_name, updated_name): global clients if client_name in clients: clients = clients.replace(client_name + ',', updated_name + ',') else: print('Client not in client\'s list') def _add_comma(): global clients clients += ',' def _get_client_name(): client_name = None while not client_name: client_name = input('What is the client name?') if client_name == 'exit': client_name = None break if not client_name: sys.exit() return client_name 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 clients') print('[U]pdate client') if __name__ == '__main__': _print_welcome() command = input() 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 = input('What is the new client name? ') update_client(client_name, updated_name) list_clients() else: print('Invalid command')

    Graias por tu respuesta

    Danelia Sanchez Sanchez

    Danelia Sanchez Sanchez

    studenthace 7 años

    Comparte tu código para que la comunidad te ayude. Saludos.

Curso Práctico de Python

Curso Práctico de Python

Aprende a programar en Python creando un CRUD desde cero. Construye una aplicación de línea de comandos, interactúa con bases de datos y maneja conceptos como clases, listas y diccionarios. Lleva tu primer proyecto Python al siguiente nivel.

Curso Práctico de Python
Curso Práctico de Python

Curso Práctico de Python

Aprende a programar en Python creando un CRUD desde cero. Construye una aplicación de línea de comandos, interactúa con bases de datos y maneja conceptos como clases, listas y diccionarios. Lleva tu primer proyecto Python al siguiente nivel.