This exercise creates a veterinary clinic management system that handles patient registration, updates, and specialized listing based on patient status. It demonstrates working with dictionaries, boolean states, and filtered data queries.
Difficulty Level: IntermediateConcepts Covered: Dictionaries, boolean states, filtered queries, conditional logic, menu systems, data filtering
pacientes=[ { "nombre":"kronos", "raza":"criollo", "edad":2, "identificacionDueño":"3935353", "estado":False }, { "nombre":"lucas", "raza":"criollo", "edad":2, "identificacionDueño":"3935353", "estado":True }, { "nombre":"mateo", "raza":"criollo", "edad":2, "identificacionDueño":"3935353", "estado":False },]while True: print("Veterinaria Daly") print("""MENU(1) registrar un nuevo paciente(2) actualizar un paciente(3) listar pacientes activos(4) listar pacientes inactivos(5) listar todos los pacientes(6) cerrar programa """) opcionMenu=input("INGRESA LA OPCION=>") if opcionMenu=="1": nombre=input("ingresa el nombre del paciente=>") raza=int(input("ingresa la raza del paciente=>")) edad=int(input("ingresa la edad del paciente=>")) identificacion=int(input("ingresa el # de identificacion del dueño del paciente=>")) estado=int(input("ingresa el estado del paciente, 'True' si esta en la vetarinaria o 'False' si ya salio de la veterinaria")) nuevoPaciente={ "nombre":nombre, "raza":raza, "edad":2, "identificacionDueño":identificacion, "estado":False }, pacientes.append(nuevoPaciente) elif opcionMenu=="2": indice=0 print("PACIENTES") for paciente in pacientes: #mostrar informacion de pacientes print(f""" id=[{indice}] Nombre={paciente["nombre"]} Raza={paciente["raza"]} Edad={paciente["edad"]} Identificacion Dueño={paciente["identificacionDueño"]} Estado={paciente["estado"]} """) indice+=1 #pedimos los nuevos datos pacienteParaActualizar=int(input("ingresa el id del paciente que quieres actualizar=>")) nuevoNombre=input("ingresa el nombre del paciente=>") nuevaRaza=int(input("ingresa la raza del paciente=>")) nuevaEdad=int(input("ingresa la edad del paciente=>")) nuevaIdentificacion=int(input("ingresa el # de identificacion del dueño del paciente=>")) nuevoEstado=int(input("ingresa el estado del paciente, 'True' si esta en la vetarinaria o 'False' si ya salio de la veterinaria")) #actualizar los nuevos datos pacientes[pacienteParaActualizar]["nombre"]=nuevoNombre pacientes[pacienteParaActualizar]["raza"]=nuevaRaza pacientes[pacienteParaActualizar]["edad"]=nuevaEdad pacientes[pacienteParaActualizar]["identificacionDueño"]=nuevaIdentificacion pacientes[pacienteParaActualizar]["estado"]=nuevoEstado elif opcionMenu=="3": indice=0 print("PACIENTES ACTIVOS") for paciente in pacientes: if paciente["estado"]==True: print(f""" id=[{indice}] Nombre={paciente["nombre"]} Raza={paciente["raza"]} Edad={paciente["edad"]} Identificacion Dueño={paciente["identificacionDueño"]} Estado={paciente["estado"]} """) indice+=1 elif opcionMenu=="4": indice=0 print("PACIENTES INACTIVOS") for paciente in pacientes: if paciente["estado"]==False: print(f""" id=[{indice}] Nombre={paciente["nombre"]} Raza={paciente["raza"]} Edad={paciente["edad"]} Identificacion Dueño={paciente["identificacionDueño"]} Estado={paciente["estado"]} """) indice+=1 elif opcionMenu=="5": indice=0 print("PACIENTES") for paciente in pacientes: if paciente["estado"]==False: print(f""" id=[{indice}] Nombre={paciente["nombre"]} Raza={paciente["raza"]} Edad={paciente["edad"]} Identificacion Dueño={paciente["identificacionDueño"]} Estado={paciente["estado"]} """) indice+=1 elif opcionMenu=="6": print("adios") break else: print("ingresastes una opcion invalida")
if opcionMenu=="1": nombre=input("ingresa el nombre del paciente=>") raza=int(input("ingresa la raza del paciente=>")) edad=int(input("ingresa la edad del paciente=>")) identificacion=int(input("ingresa el # de identificacion del dueño del paciente=>")) estado=int(input("ingresa el estado del paciente, 'True' si esta en la vetarinaria o 'False' si ya salio de la veterinaria")) nuevoPaciente={ "nombre":nombre, "raza":raza, "edad":2, "identificacionDueño":identificacion, "estado":False }, pacientes.append(nuevoPaciente)
Issues in This Code
Bug 1: The user inputs raza as an integer, but it should be a string (breed name).Bug 2: The user inputs edad but it’s hardcoded to 2 in the dictionary.Bug 3: The user inputs estado but it’s hardcoded to False in the dictionary.Bug 4: There’s a trailing comma after the dictionary, making nuevoPaciente a tuple instead of a dict.Corrected version:
nombre=input("ingresa el nombre del paciente=>")raza=input("ingresa la raza del paciente=>") # Should be stringedad=int(input("ingresa la edad del paciente=>"))identificacion=input("ingresa el # de identificacion del dueño del paciente=>") # Should be stringestado_input=input("ingresa el estado del paciente (True/False)=>")estado = True if estado_input.lower() == 'true' else FalsenuevoPaciente={ "nombre":nombre, "raza":raza, "edad":edad, # Use input value "identificacionDueño":identificacion, "estado":estado # Use input value} # No trailing commapacientes.append(nuevoPaciente)
elif opcionMenu=="2": indice=0 print("PACIENTES") for paciente in pacientes: print(f""" id=[{indice}] Nombre={paciente["nombre"]} Raza={paciente["raza"]} Edad={paciente["edad"]} Identificacion Dueño={paciente["identificacionDueño"]} Estado={paciente["estado"]} """) indice+=1 pacienteParaActualizar=int(input("ingresa el id del paciente que quieres actualizar=>")) nuevoNombre=input("ingresa el nombre del paciente=>") nuevaRaza=int(input("ingresa la raza del paciente=>")) nuevaEdad=int(input("ingresa la edad del paciente=>")) nuevaIdentificacion=int(input("ingresa el # de identificacion del dueño del paciente=>")) nuevoEstado=int(input("ingresa el estado del paciente, 'True' si esta en la vetarinaria o 'False' si ya salio de la veterinaria")) pacientes[pacienteParaActualizar]["nombre"]=nuevoNombre pacientes[pacienteParaActualizar]["raza"]=nuevaRaza pacientes[pacienteParaActualizar]["edad"]=nuevaEdad pacientes[pacienteParaActualizar]["identificacionDueño"]=nuevaIdentificacion pacientes[pacienteParaActualizar]["estado"]=nuevoEstado
This section displays all patients with their IDs, then allows updating all fields for a selected patient.
elif opcionMenu=="5": indice=0 print("PACIENTES") for paciente in pacientes: if paciente["estado"]==False: # Bug: Should show ALL patients print(f""" id=[{indice}] Nombre={paciente["nombre"]} Raza={paciente["raza"]} Edad={paciente["edad"]} Identificacion Dueño={paciente["identificacionDueño"]} Estado={paciente["estado"]} """) indice+=1
Bug in Option 5
Issue: Option 5 should list ALL patients, but it has the same condition as option 4 (only False states).Fix: Remove the if condition:
elif opcionMenu=="5": indice=0 print("TODOS LOS PACIENTES") for paciente in pacientes: print(f""" id=[{indice}] Nombre={paciente["nombre"]} Raza={paciente["raza"]} Edad={paciente["edad"]} Identificacion Dueño={paciente["identificacionDueño"]} Estado={paciente["estado"]} """) indice+=1
Problem: The code treats raza as integer when it should be string.Solution: Change input collection:
raza = input("ingresa la raza del paciente=>") # Remove int()
Index Tracking Bug in Filtered Lists
Problem: When listing active/inactive patients, the index continues from previous iterations, which may not match the actual list index.Better Approach: Use enumerate or track actual list indices:
for idx, paciente in enumerate(pacientes): if paciente["estado"]==True: print(f"id=[{idx}]...")