I'm trying to make a simple interactive for my students to practice differentiating polynomials. For some reason, when an answer is entered, Sage tries to convert it (a polynomial) to an instance of sage.structure.parent.Parent and chokes. The same code run outside of an interactive works fine. Why is Sage trying to do this conversion and how do I get it to stop?
#Create polynomial generator
poly.<x>=PolynomialRing(QQ)
#Problems correct (in a row and total)
streak = 0
tot = 0
first = True
@interact
def polyDiff(ans=input_box(label="f'(x)=", type=sage.rings.polynomial.polynomial_rational_flint.Polynomial_rational_flint)):
#Load persistent variables
global streak
global tot
global first
global poly
#Set up and display problem on first run
if (first == True):
rand_poly=poly.random_element(2)
first = False
html("f(x)=")+html(rand_poly)
#Define correct answer
corr = diff(rand_poly, x)
#Check student's answer
if (ans is not None):
if (corr == ans):
print "Correct!"
tot += 1
streak += 1
#Generate new problem
rand_poly = poly.random_element(5)
else:
html("Try again")
streak = 0
else:
print "Enter your answer"