1
    s = input(' Enter a monomial: ')
    coeff, power = s.partition('x^')
    print('{}x^{}'.format(int(coeff) * int(power), int(power) - 1)

I do not know what else is needed at the end of this code. Is there something that needs to be added in?

2 Answers 2

2

It's because you're not closing print function, one a close parenthesis at the end is missing. I suggest you to use some linter to debug and find warning and errors. The final code should be as below:

s = input(' Enter a monomial: ')
coeff, power = s.partition('x^')
print('{}x^{}'.format(int(coeff) * int(power), int(power) - 1))
Sign up to request clarification or add additional context in comments.

4 Comments

That worked!!!. However when i ran the code I ended up with these errors: Enter a monomial: 2x^12 Traceback (most recent call last): File "./derivative.py", line 4, in <module> coeff, power = s.partition('x^') ValueError: too many values to unpack (expected 2)
Yep, that makes sense because partition is splitting the input in 3 parts and you're capturing just two of those coeff, power. You can use split function instead and the replace that line as following: coeff, power = s.split('x^')
That worked like a charm!!! Results have been achieved. Thank you for your advice.
You're welcome, we're here to help each other. Don't forget try to implement a linter e.g. pylint to make debugging easier and you don't face this error next time :)
1

You missed a bracket in last line:

print('{}x^{}'.format(int(coeff) * int(power), int(power) - 1))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.