Probably off-topic here and more adapted
to Ask Sage (ask.sagemath.org) or sage-support
(groups.google.com/g/sage-support).
Here is a way.
Define a polynomial ring and its variable:
sage: R = PolynomialRing(QQ, 'X')
sage: X = R.gen()
Alternatively, use the shortcut syntax:
sage: R.<X> = QQ[]
Define a function to produce $n \sum_{i = 1}^{a} X^i$:
sage: def poly(a, n):
....: return R([0] + [n]*a)
Explanation: the polynomial ring can transform a list
of coefficients into a polynomial. The polynomial we
want has a zero constant term, followed by a monomials
for the following a powers of X, with coefficients
all equal to n.
Now use that function:
sage: poly(3, 2))
2*X^3 + 2*X^2 + 2*X
sage: poly(2, 3))
3X^2 + 3X
sage: poly(3, 2) + poly(2, 3))
2X^3 + 5X^2 + 5*X