SyntaxError: invalid syntax (print function) [closed] - python

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
>>> x=[]
>>> for i in range(10):
x.append(i)
print(x)
SyntaxError: invalid syntax
I'm working with Python 3.5. I can't seem to get the print function working when it's not part of a loop. "print" gets highlighted as the source of the syntax error, but I can't seem to isolate the cause of the error. It prints perfectly well when part of a while or for loop. It's probably caused by a really silly oversight, and I would really appreciate if somebody could point it out.

If you are typing in console, you need to hit enter twice to end that statement. Which in your case, what you did is, you wrote print inside for without indentation. So it will show syntax error.

Related

Why are my variables highlighted in blue? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I have a dataframe called propertydf.
When I run my code I get a very vague error:
propertydf = propertydf[propertydf['fixed_price'].notna()].copy()
^
SyntaxError: invalid syntax
I checked the code and the dataframe variable has changed color to blue? But not all of them.
I also noticed some other variables are suddenly blue, such as year and date.
I think this is causing the error. How can I fix it?
In the line propertydf['fixed_price'] = fix_price((propertydf.iloc[:,[4]]) you open two parenthesis but only close one (It's above the line that throws the error).

Why is it giving me this syntax error? I’m following a tutorial. (Beginner) [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
It's saying there's a syntax error (seems simple enough) but I've double-checked the video (and my brain). I don't see why it would be saying that.
Been following this tutorial and taking notes to a T (if I need to include more code let me know).
I defined "run_test" and am entering the parameters in question. Help?
You have extra opening parenthesis before ‘str(len(...))’
There should be a closing brackets for str in print statement ')' , add this and your program will work
If i am not wrong, you haven't defined the list of questions yet. If you have defined your list of questions it is probably a typing error in your code. If there is the full code under the tutorial you are doing then i would compare my code to the code from the tutorial.

I can't determine why it's raising this SyntaxError [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
https://pastebin.com/TZdMx3pM
Here's the code
This error is raised on line 291:
File "marketTrader.py", line 291
stock_list.remove(preferredStock[0])
^
SyntaxError: invalid syntax
I am runing on MacOS. Does it matter if I'm using Python 2 or 3?
Any help is greatly appreciated!
You forgot to close a parentheses on the previous line, 290.
This kind of syntax error does not depend on Python version or OS.
You could have spotted it easily using an IDE (e.g. PyCharm, EMACS) or a static analyser (e.g. pycheck).
It's a missing ')'
Check the line before:
print(': Starting Active Trader with preferred stock {}...'.format([preferredStock[0]])
stock_list.remove(preferredStock[0])
There is missing a close bracket for print.

Why does the Python repl print different things for None? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
Today I was playing with a Python dict and I found something weird:
>>> print {}.get('non-existant-key')
>>> a = {}.get('non-existant-key')
>>> print a
None
>>>
Why does the repl print an empty space with the first print and "None" after taking the step of storing the value in the variable a? The thing it tries to print is the same in both cases, so why is there be a difference?
Okay, turns out it wasn't the behaviour of the Python repl, but the (for the rest excellent) bpython repl which I always use. I didn't realise I was using bpython instead of the vanilla python when I was testing this.
In the regular pyton repl it all works as expected. I'll file a bug with bpython about this.

Python def marked as invalid syntax [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Im working on a (in-shell) geometry calculator in Python, and I get a syntax error everytime marked as the def in the below code:
def scepm(r,h):#surface-area circular-prism(cylinder)comment s.o.f. only
print(3.14159265358979323846264338327950*r**2+3.14159265358979323846264338327950*r*h)
It might be something obvious. If it is, can someone please point it out? thanks
If the syntax error is indicating the def it means that def is not valid at this point in the program. def starts a statement, so the conclusion would be that you are not starting a statement at the beginning of the line, you must have unclosed parentheses in the previous non-blank, non-comment line.
That is assuming your description is accurate: if not you could get other errors such as an indentation error, or if it indicated somewhere later in the line it could be some other issue you failed to copy exactly.
It works fine you should call the function though:
def scepm(r,h): # surface-area circular-prism(cylinder)comment s.o.f. only
print(3.14159265358979323846264338327950*r**2+3.14159265358979323846264338327950*r*h)
scepm(1,3) #function call

Categories

Resources