This question already has answers here:
Why is parenthesis in print voluntary in Python 2.7?
(4 answers)
Syntax error on print with Python 3 [duplicate]
(3 answers)
Closed 6 years ago.
I haven't done much with Python, but the code-academy course has seemed to give me some enjoyment however when I have taken my project to the actual python compiler I get an error compiling. Highly possible that code-academy just hasn't updated to a more recent version, as I've seen here that people have used this previously.
C:\Python>battleship.py
File "C:\Python\battleship.py", line 10
print " ".join(row)
^
SyntaxError: invalid syntax
For some reason I am having issues placing the source in the question, as this is my first question, so ill describe the code. Using an empty list there is a "board" created to play battleship on, with a for loop that loops through a set range appending < board.append["O"] * 5 >. Then it loops through each row in the array and then uses < print " ".join(row) >
How can I get by this and is there an alternative way that is better?
Edit: Python version 3.5.2
Related
This question already has answers here:
Python Syntax Errors with Python Anywhere
(2 answers)
Closed 5 years ago.
I'm just starting to learn Python using a raspberry pi. One of the exercises on the pi website has the following code:
for i in range(2):
print("A")
print("B")
Which the tutorial says should give the output:
A
A
B
However, when I run this code in the Python 3.5.3 IDLE, I get a syntax error, with the second "print" highlighted. Any thoughts? Here is the website I'm referring to:
https://www.raspberrypi.org/documentation/usage/python/
I believe the the second print should be indented as well because python relies on white space instead of parenthesis or brackets, so the second print isnt being counted, however, im not super great at python
This question already has answers here:
Django Python Dictionary comprehension giving syntax error
(1 answer)
Alternative to dict comprehension prior to Python 2.7
(1 answer)
Closed 5 years ago.
I need to use a code written by someone else in Python a while back, and I get a SyntaxError: invalid syntax in this line:
tfileServices = {n: s.fileName for n, s in process.services.iteritems() if s.type_() == 'TFileService'}
I am not really sure what is wrong about it, so can someone tell me why is it not working (it supposedly worked for him)? Thank you! (I am not sure what to google for to find out what is wrong, as I am not sure how the actual syntax should look like)
This question already has answers here:
f-strings giving SyntaxError?
(7 answers)
Closed 5 years ago.
I have a variable called method, it's value is POST but when I try to run print(f"{method} method is used.") it keeps giving a syntax error at the last double quote and I can't find the reason on why it does this. I am using python 3.5.2.
F-strings were a new feature introduced in Python 3.6, so of course they're not going to work in 3.5.2.
This question already has answers here:
Syntax error on print with Python 3 [duplicate]
(3 answers)
Closed 7 years ago.
I just finished learning the Python syntax at Codeacademy and decided to try and do some bits in Python proper. So I download the latest version and although my code works on Codeacademy it doesn't work in this (I assume they are different).
What I'm trying to do is get the numbers appended to the list, sum them and the print the result. Here's what I wrote:
num = []
for x in range(1,11):
if x%3==0 or x%5==0:
num.append(x)
print num
print sum(num)
What's wrong? I get a syntax error with an arrow under the 't' in 'print'.
This still doesn't work when I change the print part...so something else in the code must be wrong but it still tells me it's a print error.
Your code is valid in Python 2.x, however invalid in Python 3.x
In 3.x, print is a function now. Change
print num
print sum(num)
to
print(num)
print(sum(num))
This question already has answers here:
Syntax error on print with Python 3 [duplicate]
(3 answers)
Closed 9 years ago.
Once again Python's helpful error messages make me eat my keyboard.
I've checked the whole script forwards and backwards but can't find any "syntax error(s)".
Is there a decent debugger for Python or a helpful website which is able to scan my code for errors?
C:\Users\Daapii\Desktop>"foo.py"
File "C:\Users\Daapii\Desktop\foo.py", line 26
print "test"
^
SyntaxError: invalid syntax
Python why u no tell me more!
If this is Python 3, then the print function now requires parenthesis. Try print("test").
(EDIT: If Python continues to make you want to eat your keyboard, this might help.)
print is a function in Python 3:
print ("test")
Find other changes here: docs