Reputation: 11
I am new trying to learn to program. I downloaded Python 3.9.5 and trying a function as follows:
>>> def f(x):
return x**3
f(3)
SyntaxError: invalid syntax
What am I doing wrong or do I need to download something more?
Upvotes: 0
Views: 82
Reputation: 894
Once you hit the enter after def f(x):
, add 4 space indentation.
And then hit enter twice until you see another >>>
prompt.
>>> def f(x):
... return x**3
...
>>> f(3)
27
Upvotes: 2
Reputation: 1015
You need to add a a newline:
def f(x): return x**3
f(3)
Then it is correct syntax.
Upvotes: 2