Advertisement
teslariu

integrador2 con func

May 4th, 2023
931
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.51 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. # Ejercicio integrador
  5.  
  6. #################################################
  7. def borrar_pantalla():
  8.     import os
  9.     if os.name == "posix":
  10.         os.system("clear")
  11.     else:
  12.         os.system("cls")
  13.  
  14.  
  15. def menu():
  16.     return """
  17.    Ingrese el número de la operación que desea ejecutar:
  18.    1 - Ver la lista de alumnos.
  19.    2 - Añadir un alumno a la lista.
  20.    3 - Salir."""
  21.  
  22. def imprimir(alumnos):
  23.     if alumnos:
  24.         print("Lista de alumnos:")
  25.         for alumno in alumnos:
  26.             print(f"{alumno[0]} - {alumno[1]} cursos")
  27.     else:
  28.         print("No hay alumnos")
  29.    
  30. def agregar_alumno():
  31.     nombre = input("Ingrese el nombre del alumno: ")
  32.     while True:
  33.         cursos = input("Ingrese la cantidad de cursos: ")
  34.         if cursos.isdecimal() and int(cursos):
  35.             return [nombre, cursos]
  36.         else:
  37.             print("Error en el ingreso de la cantidad de cursos")
  38.                
  39.        
  40.    
  41.  
  42.  
  43. ###########################################
  44. alumnos = []
  45.  
  46. while True:
  47.     print(menu())
  48.     opcion = input(">>> ")
  49.    
  50.     if opcion == "1":
  51.         imprimir(alumnos)
  52.    
  53.     elif opcion == "2":
  54.         alumno = agregar_alumno()
  55.         alumnos.append(alumno)
  56.        
  57.        
  58.     elif opcion == "3":
  59.         print("¡Gracias por utilizar el programa!")
  60.         break
  61.    
  62.     else:
  63.         print("La opción ingresada no es correcta, vuelva a intentarlo.")    
  64.    
  65.     input()
  66.     borrar_pantalla()
  67.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement