1

I am learning Python code. When I create a function it works fine but when I go to call the function I get a syntax error, what is wrong with my code?

    >>> def someFunction(a,b):
            print (a+b)
       someFunction(12,451)
    SyntaxError: invalid syntax
2
  • If you find Cyber's answer fixes the problem, you can mark it as the accepted answer and up-vote it (assuming you have enough reputation to do so). Commented Jan 23, 2015 at 19:00
  • @NoctisSkytower I have marked it as the correct answer but do not yet have enough reputation to mark it up. Thanks. Commented Jan 25, 2015 at 15:37

1 Answer 1

3

You need to hit enter one more time after your print statement, it thinks your function call was part of the function definition. You'll know when you completed the function definition when it prompts you for a new statement with

>>>

So it would look like

>>> def someFunction(a,b):
        print (a+b)

>>> someFunction(12,451)
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, this was the problem!
@SeanLloyd note that this is specific to IDLE. If you were entering your code in a .py file and running it, it would execute just fine.

Your Answer

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