Somehow the line breaks were ignored in my previous post.
The lines that gave errors in the problem were:
7 x = var("x",domain=QQ)
8 y = var("y",domain=QQ)
The error was:
ValueError: Rational Field: domain must be one of 'complex', 'real', 'positive' or 'integer'