Added missing grading.py file

This commit is contained in:
Tom van Woudenberg 2024-05-27 09:50:01 +02:00
parent 41f5701aab
commit ebfede3879
2 changed files with 17 additions and 1 deletions

View file

@ -1,4 +1,4 @@
#from grading import check
from grading import check
from math import isclose
tolerance = 0.001

16
book/examples/grading.py Normal file
View file

@ -0,0 +1,16 @@
from IPython.display import display
import ipywidgets as widgets
def check(f):
def wrapper(*args, **kwargs):
output = widgets.Output()
button = widgets.Button(description="Check Answer(s)")
@output.capture(clear_output=True,wait=True)
def _inner_check(button):
try:
f(*args, **kwargs)
except:
print("Something went wrong, have you filled all the functions and run the cells?")
button.on_click(_inner_check)
display(button, output)
return wrapper