Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- import os
- import time
- # alumnos = {"Juan":3, "Ana":5, "Josefa":6}
- alumnos = {}
- def borrar_pantalla():
- if os.name == "posix":
- os.system ("clear")
- else:
- os.system ("cls")
- def ingresar_cursos():
- while True:
- tiempo = input("Ingrese los cursos: ")
- if tiempo.isdecimal() and tiempo != "0":
- return int(tiempo)
- print("Error: debe ingresar un entero positivo")
- def ingresar_nombre():
- while True:
- nombre = input("Ingrese un nombre: ")
- if nombre.isdecimal() or not nombre or nombre.isspace():
- print("Error: no ha ingresado un nombre válido")
- else:
- return nombre
- def menu():
- return """
- Ingrese el número de la operación que desea ejecutar:
- 1 - Ingresar un alumno.
- 2 - Ver la lista de los alumnos ingresados.
- 3 - Ver la cantidad de cursos de un alumno.
- 4 - Salir.
- """
- while True:
- borrar_pantalla()
- print(menu())
- opcion = input(">>> ")
- if opcion == "1":
- nombre = ingresar_nombre()
- cursos = ingresar_cursos()
- alumnos[nombre] = cursos
- print("¡El alumno fue añadido a la lista!")
- time.sleep(3)
- elif opcion == "2":
- if alumnos:
- print("Lista de alumnos:")
- for k,v in alumnos.items():
- print(f"{k} - {v} cursos")
- _ = input("Presione cualquier tecla para continuar")
- else:
- print("No hay alumnos")
- time.sleep(3)
- elif opcion == "3":
- nombre = input("Ingrese el nombre: ")
- if nombre in alumnos.keys():
- print(f"Cantidad de cursos: {alumnos[nombre]}")
- else:
- print(f"No existe el alumno {nombre}")
- time.sleep(3)
- elif opcion == "4":
- print("Gracias por utilizar este programa")
- break
- else:
- print("La opción ingresada no es correcta, vuelva a intentarlo.")
- time.sleep(3)
Advertisement
Add Comment
Please, Sign In to add comment