55 lines
1.3 KiB
Python
55 lines
1.3 KiB
Python
|
import os
|
||
|
from time import sleep
|
||
|
|
||
|
clear = lambda: os.system('clear') if os.name == 'posix' else os.system('cls')
|
||
|
tab='\n'+' '*4
|
||
|
|
||
|
def excp_handler(function):
|
||
|
def wrapper(*args, **kwargs):
|
||
|
try:
|
||
|
function(*args, **kwargs)
|
||
|
except Exception:
|
||
|
print("Lee atentamente las instrucciones e intenta nuevamente")
|
||
|
sleep(3)
|
||
|
return wrapper
|
||
|
|
||
|
def opcs_default():
|
||
|
print(""" v) Volver
|
||
|
s) Salir""")
|
||
|
|
||
|
def enter_continue():
|
||
|
input("\n\tPresiona Enter para continuar\n")
|
||
|
|
||
|
@excp_handler
|
||
|
def run_func(func):
|
||
|
print(tab, func.__doc__, '\n')
|
||
|
func()
|
||
|
enter_continue()
|
||
|
|
||
|
def user_input(i):
|
||
|
try:
|
||
|
selection = input("\n Ingresa una opción: ")
|
||
|
if selection in 'sSvV':
|
||
|
return selection.lower()
|
||
|
selection = int(selection)
|
||
|
if 0 < selection <= i:
|
||
|
clear()
|
||
|
return selection
|
||
|
else:
|
||
|
raise Exception
|
||
|
except Exception:
|
||
|
print("Debes ingresar una opción válida")
|
||
|
sleep(2)
|
||
|
return 0
|
||
|
|
||
|
def print_challenges(exercises):
|
||
|
ex = exercises()
|
||
|
i = 0
|
||
|
funcs = list(vars(exercises))[1:-3]
|
||
|
while i < len(funcs):
|
||
|
print(f"{i+1}) ".rjust(8), end='')
|
||
|
print(vars(exercises).get(funcs[i]).__doc__)
|
||
|
i+=1
|
||
|
opcs_default()
|
||
|
return i, ex
|