1

I am trying to build a code that spits out y given f(x). Apparently, mine isn't working. Can you please help?

def f(n):
    '''The Function'''
    return -5(n**5)+69.0(n**2)-47


print f(2)

Thank you!

1
  • By the way, the error shown is: Line 3: TypeError: 'int' object is not callable Commented Apr 7, 2015 at 2:23

2 Answers 2

3

Use this:

return (-5*(n**5))+(69.0*(n**2))-47

The algebraic notation you are using i.e. omitting the '*' sign causes python to think that you are trying to make a function call:

69.0(n**2)  # python thinks 69.0 is a function name and n**2 is the parameter of this call

That is why the '*' operator is necessary, between two operands.

Sign up to request clarification or add additional context in comments.

1 Comment

Good answer, but you can make it a lot better if you update it to explain why you made the changes you did.
2

I think the problem is that you're using algebraic notation where (I presume) you want to multiply. For instance, instead of:

-5(n**5)

you want

-5 * (n ** 5)

A single asterisk ("*") is multiplication in Python (and many other programming languages).

If you just put parentheses directly after something, Python is interpreting that as you attempting to call that thing. It might be more obvious with named variables:

a = 5
a(n ** 5)

Is line 2 a function call, or multiplication? In Python, it's unambiguously the latter, but you can't call integers, so you get an exception like TypeError: 'int' object is not callable

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.