# Revision history [back]

### Getting the leading term from random polynomials

Hi there. I'm writing self generating algebra tests for a class I teach. I'm using this code to generate random polynomials of various degrees up to 8 with single digit integer coefficients:

R.<x> = PolynomialRing(ZZ)
po = {}
for index in range(1, 10):          # Picks random polynomials for use.
deg = ZZ.random_element(0, 8)
po["ly{0}".format(index)] = R.random_element(deg, -9, 10)


To make the answer key, I'm attempting to show the polynomial, its degree, its leading term, and its leading coefficient of each polynomial. My code for that looks like:

po['ly1']
po['ly1'].degree(x)
po['ly1'].lt(x)
po['ly1'].lc(x)


Getting the degree works, but not the leading term or the leading coefficient. The errors I get are:

AttributeError: 'sage.rings.polynomial.polynomial_integer_dense_flint.Polynomial_integer_dense_flint' object has no attribute 'lt'


and

AttributeError: 'sage.rings.polynomial.polynomial_integer_dense_flint.Polynomial_integer_dense_flint' object has no attribute 'lc'


respectively.

I have been unable to ascertain from the documentation what the correct commands should actually look like. I have tried both ".lt()" and ".lt(x)" and similar for .lc. Please let me know, if you can, what my error is. Thank you.