In [1]:
def add(a, b):
result = a + b
return result
In [2]:
add(2, 5)
Out[2]:
In [3]:
add(-20, 30)
Out[3]:
So that we can interactively provide inputs
Display the result
In [4]:
from ipywidgets import interact
In [5]:
interact(add, a=10, b=20)
In [6]:
from ipywidgets.widgets import IntText
In [7]:
aText = IntText(min=0, max=10, value=2)
bText = IntText(min=0, max=10, value=2)
interact(add, a=aText, b=bText)
In [8]:
def sub(a, b, verbose=False):
result = a - b
if verbose:
return "a - b = %s" % (result)
else:
return result
In [9]:
from ipywidgets.widgets import IntSlider
In [10]:
aSlider = IntSlider(min=-100, max=100, value=0)
bSlider = IntSlider(min=-100, max=100, value=0)
interact(sub,
a=aSlider,
b=bSlider,
verbose=True,
)