insert a record in python

0

I have the following algorithm where I have several modules and they ask me to do one that is to insert but I do not understand what it means to insert it may not be understood what I ask but any help serves

class PUNTERO():
    def __init__(self):
        self.rol = 0
        self.nombre = "" 
        self.edad = 0
        self.next = None    

def AgregarALaCola(base):
    q = PUNTERO()
    print("Ingrese datos de persona que se agregará a la cola")
    q.rol = int(input("Rol: "))
    q.nombre = input("Nombre: ")
    q.edad = int(input("Edad: "))
    q.next = None
    if base == None:
       base = q
    else:
        p = base
        while p.next != None:
            p = p.next
        p.next = q
    return base

def Listar(base):
    print("LISTADO DE PERSONAS") 
    print("    ROL             NOMBRE             EDAD")
    print("    ===             ======             ====")
    p = base
    while p != None:   
        print(repr(p.rol).ljust(7), "   ", p.nombre.ljust(20), "   ", repr(p.edad).rjust(5))
        p = p.next   
    print("FIN LISTADO") 

def ConsultarPorRol(base): 
    # Completar este módulo


    if base == None:
        print("Error, lista vacia")
    else:
        f = int(input("ingrese rol a comparar: "))
        p = base
    while p != None:

        if f == p.rol:
            print("rol obtenido")
            print (repr(p.rol).ljust(7), "   ", p.nombre.ljust(20), "   ", repr(p.edad).rjust(5))
        p = p.next
    print() 

def Eliminar (base): 
    if base == None: 
        print("Lista vacía. No se puede eliminar nodos")
    else: 
        rolElim = int(input("Ingrese Rol de persona a eliminar: "))
        p = base
        while (p != None) and (p.rol != rolElim):
            pant = p
            p = p.next
        if p == None:
            print("No se encontró ese Rol. No se elimina")
        else: 
            if p == base:
                base = base.next
            else: 
                pant.next = p.next
    return base

def Insertar(base): 
    # Completar este módulo
    return base 

def Estadisticas(base): 
    # Completar este módulo 
    # Debe entregar: Cantidad de personas, Promedio de edad, Cantidad de menores y de mayores, Edad mayor
    print()

# PROGRAMA PRINCIPAL
base = None
opcion = "0"
while opcion != "9": 
    print("Ingrese opción: 1=Agregar, 2=Listar, 3=Consultar, 4=Eliminar, 5=Insertar, 6=Estadísticas, 9=Salir")
    opcion = input("Opción = ")
    print()
    if opcion == "1":   base = AgregarALaCola(base)
    if opcion == "2":   Listar(base)
    if opcion == "3":   ConsultarPorRol(base)
    if opcion == "4":   base = Eliminar(base)
    if opcion == "5":   base = Insertar(base)
    if opcion == "6":   Estadisticas(base)
    print(); print()
input("FIN DEL PROCESO")
    
asked by Miguel Rovlich Bastias 28.10.2018 в 05:33
source

0 answers