This exercise implements a full CRUD (Create, Read, Update, Delete) system for managing coder records. You’ll work with lists of dictionaries, create a menu-driven interface, and perform all four fundamental database operations.
Difficulty Level: IntermediateConcepts Covered: Lists, dictionaries, while loops, menu systems, data manipulation, indexing
coders=[ { "nombre":"Javier", "edad":25, "riwipoints":4 }, { "nombre":"lucas", "edad":18, "riwipoints":8 }, { "nombre":"pablo", "edad":30, "riwipoints":5 }, { "nombre":"judas", "edad":19, "riwipoints":0 }, { "nombre":"mateo uno", "edad":36, "riwipoints":9 }]while True: print(""" MENU (1) registrar un nuevo coder (2) actualizar coder (3) eliminar coder (4) listar coders (5) cerrar programa """) opcionMenu=input("INGRESA LA OPCION=>") if opcionMenu=="1": nombre=input("ingresa el nombre del coder=>") edad=int(input("ingresa la edad del coder=>")) riwipoints=int(input("ingresa los riwipoints del coder=>")) nuevoCoder={ "nombre":nombre, "edad":edad, "riwipoints":riwipoints } coders.append(nuevoCoder) elif opcionMenu=="2": indice=0 for coder in coders: #mostrar informacion de coders print(f""" id=[{indice}] Nombre={coder["nombre"]} Edad={coder["edad"]} Riwipoints={coder["riwipoints"]} """) indice+=1 #pedimos los nuevos datos coderParaActualizar=int(input("ingresa el id del coder que quieres actualizar=>")) nuevoNombre=input("ingresa el nuevo nombre del coder=>") nuevaEdad=int(input("ingresa la nueva edad del coder=>")) nuevosRiwipoints=int(input("ingresa los nuevos riwipoints del coder=>")) #actualizar los nuevos datos coders[coderParaActualizar]["nombre"]=nuevoNombre coders[coderParaActualizar]["edad"]=nuevaEdad coders[coderParaActualizar]["riwipoints"]=nuevosRiwipoints elif opcionMenu=="3": indice=0 for coder in coders: print(f"id=[{indice}] - {coder["nombre"]}") indice+=1 coderAeliminar=int(input("ingrese el ID del coder que quiere eliminar")) del coders[coderAeliminar] elif opcionMenu=="4": print("lista de coders") for coder in coders: print(f""" NOMBRE CODER= {coder["nombre"]} EDAD= {coder["edad"]} RIWIPOINTS= {coder["riwipoints"]} """) elif opcionMenu=="5": print("aca vamos a cerrar") break else: print("ingresastes una opcion invalida")
coders=[ { "nombre":"Javier", "edad":25, "riwipoints":4 }, # ... more coders]
Data Structure: A list of dictionaries. Each dictionary represents a coder with three properties: nombre (name), edad (age), and riwipoints (points). This structure allows easy access to individual properties while keeping related data together.
while True: print(""" MENU (1) registrar un nuevo coder (2) actualizar coder (3) eliminar coder (4) listar coders (5) cerrar programa """) opcionMenu=input("INGRESA LA OPCION=>")
Why while True?
The while True loop creates an infinite loop that keeps the program running until the user explicitly chooses to exit (option 5). This pattern is common in menu-driven applications where you want continuous interaction until the user decides to quit.
if opcionMenu=="1": nombre=input("ingresa el nombre del coder=>") edad=int(input("ingresa la edad del coder=>")) riwipoints=int(input("ingresa los riwipoints del coder=>")) nuevoCoder={ "nombre":nombre, "edad":edad, "riwipoints":riwipoints } coders.append(nuevoCoder)
1
Collect Input
Gather all necessary information from the user
2
Create Dictionary
Build a new dictionary object with the collected data
3
Add to List
Use .append() to add the new coder to the end of the list
elif opcionMenu=="2": indice=0 for coder in coders: print(f""" id=[{indice}] Nombre={coder["nombre"]} Edad={coder["edad"]} Riwipoints={coder["riwipoints"]} """) indice+=1 coderParaActualizar=int(input("ingresa el id del coder que quieres actualizar=>")) nuevoNombre=input("ingresa el nuevo nombre del coder=>") nuevaEdad=int(input("ingresa la nueva edad del coder=>")) nuevosRiwipoints=int(input("ingresa los nuevos riwipoints del coder=>")) coders[coderParaActualizar]["nombre"]=nuevoNombre coders[coderParaActualizar]["edad"]=nuevaEdad coders[coderParaActualizar]["riwipoints"]=nuevosRiwipoints
Index Tracking: The indice variable manually tracks the position of each coder. This allows users to reference coders by a numeric ID. The update uses bracket notation to modify dictionary values directly.
elif opcionMenu=="3": indice=0 for coder in coders: print(f"id=[{indice}] - {coder["nombre"]}") indice+=1 coderAeliminar=int(input("ingrese el ID del coder que quiere eliminar")) del coders[coderAeliminar]
The del statement removes an element from the list at the specified index. After deletion, all subsequent elements shift down one position.
elif opcionMenu=="4": print("lista de coders") for coder in coders: print(f""" NOMBRE CODER= {coder["nombre"]} EDAD= {coder["edad"]} RIWIPOINTS= {coder["riwipoints"]} """)
This simple loop iterates through all coders and displays their information in a formatted way.
MENU(1) registrar un nuevo coder(2) actualizar coder(3) eliminar coder(4) listar coders(5) cerrar programaINGRESA LA OPCION=>1ingresa el nombre del coder=>Mariaingresa la edad del coder=>28ingresa los riwipoints del coder=>7MENU(1) registrar un nuevo coder(2) actualizar coder(3) eliminar coder(4) listar coders(5) cerrar programaINGRESA LA OPCION=>4lista de codersNOMBRE CODER= JavierEDAD= 25RIWIPOINTS= 4NOMBRE CODER= lucasEDAD= 18RIWIPOINTS= 8... [more coders]NOMBRE CODER= MariaEDAD= 28RIWIPOINTS= 7