Solve simple derivative questions
Trust the math. If exp&lt;0 and cf&lt;0, their product will be positive, so abs is redundant. BTW, in case of elif exp &lt; 0, call to abs leads to an incorrect answer.
In any case, \$(ax^n)'\$ always equals to \$anx^{n-1}\$. Mathematically speaking there are no special cases. There are special cases when it comes to printing:


\$n = 0\$: you (correctly) print 0
\$n = 1\$: you print x^0, but it is better to omit it altogether
\$n = 2\$: you print x^1, but it is better to print just x.
\$n &lt; 0\$: consider printing parenthesis around the exponent.

Separate concerns. The derivative shall only compute the derivative. Input shall be handled separately.
The call to derivative should be conditionalized:

if __name__ == `__main__`:
    derivative()


This enables you to import your code in another project.