teslariu

integrador final

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