teslariu

integrador version final

Jul 8th, 2023
677
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.86 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. def ingresar_nombre():
  5.     while True:
  6.         nombre = input("Ingrese el nombre del alumno: ")
  7.         if nombre and not nombre.isspace():
  8.             return nombre
  9.         else:
  10.             print("Error: debe ingresar un nombre")
  11.  
  12. def ingresar_cursos():
  13.     while True:
  14.         cursos = input("Ingrese la cantidad de cursos: ")
  15.         if cursos.isdecimal() and cursos != "0":
  16.             return int(cursos)
  17.         else:
  18.             print("Error: debe ingresar un nro entero positivo")
  19.  
  20.  
  21.  
  22. def imprimir(alumnos):
  23.     if not alumnos:
  24.         print("No hay alumnos")
  25.            
  26.     else:
  27.         print("Lista de alumnos:")
  28.         for k,v in alumnos.items():  
  29.             print(f"{k} - {v} cursos")
  30.  
  31.    
  32. def menu():
  33.     return """
  34.    Ingrese el número de la operación que desea ejecutar:
  35.    1 - Ingresar un alumno
  36.    2 - Ver lista de alumnos
  37.    3 - Ver cursos de un alumno
  38.    4 - Salir
  39.    """
  40.  
  41.  
  42.    
  43. def buscar_cursos():
  44.     nombre = input("Ingrese el nombre del alumno: ")
  45.     if nombre in alumnos.keys():
  46.         return f"Cantidad de cursos: {alumnos[nombre]}"
  47.     else:
  48.         return "Alumno no hallado"
  49.  
  50.  
  51.  
  52. # Estructura de datos: diccionario
  53. # alumnos = {"Juana": 3, "Ana":6, "Jose":8}
  54. alumnos = {}
  55.  
  56.  
  57.  
  58. while True:
  59.     print(menu())
  60.  
  61.     opcion = input(">>> ")
  62.  
  63.     if opcion == "1":
  64.         nombre = ingresar_nombre()
  65.         cursos = ingresar_cursos()
  66.         alumnos[nombre] = cursos
  67.         print("¡El alumno fue añadido a la lista!")
  68.  
  69.  
  70.     elif opcion == "2":
  71.         imprimir(alumnos)
  72.    
  73.                    
  74.     elif opcion == "3":
  75.         cursos = buscar_cursos()
  76.         print(cursos)
  77.        
  78.        
  79.     elif opcion == "4":
  80.         print("Gracias por utilizar este programa")
  81.         break
  82.  
  83.     else:
  84.         print("Opción equivocada")
  85.  
Advertisement
Add Comment
Please, Sign In to add comment