Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- """
- Ejemplo:
- alumnos = {"Juan":3, "Ana":5, "Tito":4}
- Lista de alumnos:
- Pablo - 3 cursos
- """
- alumnos = {}
- ############## funciones #######################
- def menu():
- print("\nAdministración de alumnos")
- eleccion = input(
- """
- Elige una opcion:
- 1- Ingresar alumno
- 2- Ver lista de alumnos
- 3- Ver cantidad de cursos de un alumno
- 4- salir
- """)
- return eleccion
- def ingresar_nombre():
- while True:
- nombre = input("Ingrese el nombre del alumno: ")
- if not nombre.isspace() and len(nombre):
- return nombre
- else:
- print("No puede dejar el nombre en blanco")
- def ingresar_cursos():
- while True:
- cursos = input("Ingrese la cantidad de cursos suscriptos: ")
- if cursos.isdecimal() and cursos!="0":
- return int(cursos)
- else:
- print("Error, debe ingresar un nro entero mayor a cero")
- def imprimir(alumnos):
- if alumnos:
- print("Lista de alumnos:")
- for nombre,cursos in alumnos.items():
- print(f"{nombre} - {cursos} cursos")
- else:
- print("No hay alumnos inscriptos")
- def ver_cursos(nombre, alumnos):
- nombres = list(alumnos.keys())
- if nombre in nombres:
- print(f"{nombre} - {alumnos[nombre]} cursos")
- else:
- print(f"No existe el alumno {nombre}")
- def salir():
- print("gracias por utilizar esta aplicacion.")
- ############## main ############################
- while True:
- eleccion = menu()
- if eleccion == "1":
- nombre = ingresar_nombre()
- cursos = ingresar_cursos()
- alumnos[nombre] = cursos
- elif eleccion == "2":
- imprimir(alumnos)
- elif eleccion == "3":
- nombre = ingresar_nombre()
- ver_cursos(nombre,alumnos)
- elif eleccion == "4":
- salir()
- break
- else:
- print("Opción incorrecta")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement