Advertisement
teslariu

integrador con funciones

Apr 4th, 2022
981
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.79 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. """
  5. Ejemplo:
  6. alumnos = {"Juan":3, "Ana":5, "Tito":4}
  7.  
  8. Lista de alumnos:
  9. Pablo - 3 cursos
  10.  
  11. """
  12. alumnos = {}
  13.  
  14. ##############  funciones   #######################
  15.  
  16. def menu():
  17.     print("\nAdministración de alumnos")
  18.     eleccion = input(
  19.     """
  20.     Elige una opcion:
  21.     1- Ingresar alumno
  22.     2- Ver lista de alumnos
  23.     3- Ver cantidad de cursos de un alumno
  24.     4- salir
  25.     """)
  26.     return eleccion
  27.  
  28.    
  29.    
  30. def ingresar_nombre():
  31.     while True:
  32.         nombre = input("Ingrese el nombre del alumno: ")
  33.         if not nombre.isspace() and len(nombre):
  34.             return nombre
  35.         else:
  36.             print("No puede dejar el nombre en blanco")
  37.  
  38.            
  39.            
  40. def ingresar_cursos():
  41.     while True:
  42.         cursos = input("Ingrese la cantidad de cursos suscriptos: ")
  43.         if cursos.isdecimal() and cursos!="0":
  44.             return int(cursos)
  45.         else:
  46.             print("Error, debe ingresar un nro entero mayor a cero")
  47.    
  48.  
  49. def imprimir(alumnos):
  50.     if alumnos:
  51.         print("Lista de alumnos:")
  52.         for nombre,cursos in alumnos.items():
  53.             print(f"{nombre} - {cursos} cursos")
  54.     else:
  55.         print("No hay alumnos inscriptos")
  56.    
  57.    
  58. def ver_cursos(nombre, alumnos):
  59.     nombres = list(alumnos.keys())
  60.     if nombre in nombres:
  61.         print(f"{nombre} - {alumnos[nombre]} cursos")
  62.     else:
  63.         print(f"No existe el alumno {nombre}")
  64.        
  65.        
  66. def salir():
  67.     print("gracias por utilizar esta aplicacion.")
  68.    
  69.  
  70. ##############    main     ############################
  71.  
  72. while True:
  73.     eleccion = menu()
  74.    
  75.     if eleccion == "1":
  76.         nombre = ingresar_nombre()
  77.         cursos = ingresar_cursos()
  78.         alumnos[nombre] = cursos
  79.    
  80.    
  81.     elif eleccion == "2":
  82.         imprimir(alumnos)
  83.        
  84.            
  85.     elif eleccion == "3":
  86.         nombre = ingresar_nombre()
  87.         ver_cursos(nombre,alumnos)
  88.        
  89.        
  90.     elif eleccion == "4":
  91.         salir()
  92.         break
  93.  
  94.        
  95.     else:
  96.         print("Opción incorrecta")
  97.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement