from ipywidgets import interact
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
import nbinteract as nbi
                def f(x):
    return x
                interact(f, x=10);
                interact(f, x=True);
                def square(x):
    return x * x
w = interact(square, x=10);
                def friends(name, number):
    return '{} has {} friends!'.format(name, number)
                interact(friends, name='Sam', number={'One': 1, 'Five': 5, 'Ten': 10});
                from matplotlib import pyplot as plt
rolls = np.random.choice([1, 2, 3, 4, 5, 6], size=300)
averages = np.cumsum(rolls) / np.arange(1, 301)
def x_vals(num_rolls):
    return range(num_rolls)
def y_vals(xs):
    return averages[:len(xs)]
def plotting_func(num_rolls):
    plt.plot(x_vals(num_rolls), y_vals(x_vals(num_rolls)))
interact(plotting_func, num_rolls=(0,100));
                def x_vals(n):
    return np.arange(n)
def y_vals(xs, n):
    return xs ** n
nbi.line(x_vals, y_vals,
         n=(1, 10))
                from matplotlib import pyplot as plt
# nbi:right
@interact(x=(0, 10))
def plot(x):
    plt.plot(np.arange(x), np.arange(x) ** 2)
plt.show()
                # nbi:left
@interact(x=(0, 10))
def square(x):
    return x * x