Interactive: Differentiating Practice (functions read from a file)

558 days ago by lhjruo

Interactive application for practicing differentiating functions (read from a file)

Lauri Ruotsalainen, 2010

Please note: This program requires a file (functions.txt) attached to the worksheet containing the functions, one on each line.

Picture:


 

# Interactive application for practicing differentiating functions (read from a file) # Lauri Ruotsalainen, 2010 functions = [l.strip() for l in file(DATA+"functions.txt", "rt")] function(x) = functions[0] ex_counter = 0 sol_counter = 0 new_ex_state = True solution_state = True @interact def deriv_practice2(answer = input_box(label="Answer:"), new_exercise = checkbox(default=False, label="New Exercise"), show_solution = checkbox(default=False, label="Show Solution")): global functions, function, ex_counter, sol_counter, new_ex_state, solution_state if ex_counter < len(functions): if answer == derivative(function(x)): html("$\\text{Very good!}$") sol_counter += 1 new_ex_state = new_exercise elif answer and show_solution != solution_state and new_exercise != new_ex_state: html("$\\text{You've made an error. Try again!}$") if new_exercise == new_ex_state: new_ex_state = not new_exercise ex_counter += 1 if ex_counter < len(functions): html("$\\text{New exercise:}$") function(x) = functions[ex_counter] if ex_counter == len(functions): html("$\\text{No more exercises. You got %s/%s right!}$"%(sol_counter, len(functions))) else: html("$\\text{Calculate the derivate: }\;\;\;\;%s$<br>"%latex(function(x))) if show_solution == solution_state: solution_state = not show_solution html("$\\text{Answer: }\;\;\;\;%s$<br>"%latex(derivative(function(x)))) 
       

Click to the left again to hide and once more to show the dynamic interactive window