Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- import os
- alumnos = {}
- def borrar_pantalla():
- if os.name == "posix":
- os.system("clear")
- else:
- os.system("cls")
- def menu():
- return """
- Menu de opciones
- --------------------------------
- 1 - Ver la lista de alumnos.
- 2 - Añadir un alumno a la lista.
- 3 - Ver cantidad de cursos de un alumno
- 4 - Salir.
- --------------------------------
- """
- def imprimir(alumnos):
- if not alumnos:
- print("No hay alumnos")
- else:
- print("Lista de alumnos")
- for k,v in alumnos.items():
- print(f"{k} - {v} cursos")
- def ingresar_nombre():
- while True:
- nombre = input("Ingrese el nombre del alumno: ")
- if nombre.isspace() or not nombre or not nombre.isalpha():
- print("Error: nombre inválido")
- else:
- return nombre
- def ingresar_cursos():
- while True:
- cursos = input("Ingrese la cantidad de cursos: ")
- if cursos.isnumeric() and int(cursos):
- cursos = int(cursos)
- return cursos
- else:
- print("Debe ingresar un número entero positivo")
- def ingresar_alumno():
- nombre = ingresar_nombre()
- cursos = ingresar_cursos()
- return [nombre,cursos]
- while True:
- borrar_pantalla()
- print(menu())
- opcion = input("Ingrese su opción: ")
- if opcion == "1":
- imprimir(alumnos)
- input("\nPresione cualquier tecla para continuar...")
- elif opcion == "2":
- nombre, cursos = ingresar_alumno()
- alumnos[nombre] = cursos
- print("¡El alumno fue añadido a la lista!")
- input("\nPresione cualquier tecla para continuar...")
- elif opcion == "3":
- nombre = ingresar_nombre()
- nombres = list(alumnos.keys())
- if nombre in nombres:
- print(f"{nombre} - {alumnos[nombre]} cursos")
- else:
- print(f"Alumno {nombre} no hallado")
- input("\nPresione cualquier tecla para continuar...")
- elif opcion == "4":
- print("¡Gracias por utilizar el programa!")
- break
- else:
- print("Opción incorrecta")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement