Advertisement
teslariu

integrador-final

Sep 5th, 2023
845
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.99 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. import os
  5.  
  6. alumnos = {}
  7.  
  8. def borrar_pantalla():
  9.     if os.name == "posix":
  10.         os.system("clear")
  11.     else:
  12.         os.system("cls")
  13.  
  14.  
  15.  
  16. def menu():
  17.     return """
  18.         Menu de opciones
  19.     --------------------------------
  20.     1 - Ver la lista de alumnos.
  21.     2 - Añadir un alumno a la lista.
  22.     3 - Ver cantidad de cursos de un alumno
  23.     4 - Salir.
  24.     --------------------------------
  25.     """
  26.    
  27. def imprimir(alumnos):
  28.     if not alumnos:
  29.         print("No hay alumnos")
  30.     else:
  31.         print("Lista de alumnos")
  32.         for k,v in alumnos.items():
  33.             print(f"{k} - {v} cursos")
  34.    
  35.  
  36. def ingresar_nombre():
  37.     while True:
  38.         nombre = input("Ingrese el nombre del alumno: ")
  39.         if nombre.isspace() or not nombre or not nombre.isalpha():
  40.             print("Error: nombre inválido")
  41.         else:
  42.             return nombre
  43.            
  44.  
  45. def ingresar_cursos():
  46.     while True:
  47.         cursos = input("Ingrese la cantidad de cursos: ")
  48.         if cursos.isnumeric() and int(cursos):
  49.             cursos = int(cursos)
  50.             return cursos
  51.         else:
  52.             print("Debe ingresar un número entero positivo")
  53.    
  54.  
  55. def ingresar_alumno():
  56.     nombre = ingresar_nombre()
  57.     cursos = ingresar_cursos()
  58.     return [nombre,cursos]
  59.  
  60.  
  61.  
  62.  
  63. while True:
  64.     borrar_pantalla()                                    
  65.     print(menu())
  66.     opcion = input("Ingrese su opción: ")
  67.    
  68.     if opcion == "1":
  69.         imprimir(alumnos)
  70.         input("\nPresione cualquier tecla para continuar...")
  71.                
  72.     elif opcion == "2":
  73.         nombre, cursos = ingresar_alumno()
  74.         alumnos[nombre] = cursos
  75.         print("¡El alumno fue añadido a la lista!")
  76.         input("\nPresione cualquier tecla para continuar...")
  77.        
  78.     elif opcion == "3":
  79.         nombre = ingresar_nombre()
  80.         nombres = list(alumnos.keys())
  81.         if nombre in nombres:
  82.             print(f"{nombre} - {alumnos[nombre]} cursos")
  83.         else:
  84.             print(f"Alumno {nombre} no hallado")
  85.        
  86.        
  87.         input("\nPresione cualquier tecla para continuar...")
  88.    
  89.     elif opcion == "4":
  90.         print("¡Gracias por utilizar el programa!")
  91.         break
  92.        
  93.     else:
  94.         print("Opción incorrecta")
  95.        
  96.        
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement