Syntax error its there but where? [duplicate] - python

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

Related

Python 3.5.2 print function not working [duplicate]

This question already has answers here:
What does "SyntaxError: Missing parentheses in call to 'print'" mean in Python?
(11 answers)
Closed 4 years ago.
I am using python version 3.5.2 and the print function isn't working for me. THis is the code. I recieve an error saying: "missing preantheses in calling to print"
print 'Output After Training:'
thanks
Add the parenthesis:
print('Output After Training:')
If you need compatibility for code so works with Python 2 or 3, use:
from __future__ import print_function
at the start of the code file and then use Python 3 way of using print().
Learn more about print() in Python 3 at:
https://www.python-course.eu/python3_print.php
The answer to your question is in the error... missing parentheses in calling to print
Python3 requires you to use parentheses when using print - i.e. print("text")

Simple three line python script not printing expected output... syntax error? [duplicate]

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

"EOF when reading a line" Python error [duplicate]

This question already has answers here:
Python 3: EOF when reading a line (Sublime Text 2 is angry)
(5 answers)
Closed 5 years ago.
name = input('Hey what is your name?: ')
print('nice to meet you ',name)
Whenever I try to run this I receive the following error :
"EOF when reading a line".
Could anyone help me with this?
Just a guess: you need to run this in a terminal (it does work when run like this). I am thinking that your code does not have any chance to get any input (hence the End Of File warning).

Python " ".join() syntax error [duplicate]

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

Showing Syntax Error while try to output the dictionary or a list value [duplicate]

This question already has answers here:
Syntax error on print with Python 3 [duplicate]
(3 answers)
Closed 9 years ago.
I am a amature in Python,using the python33 version.The problem i am facing while i want to get output of a list of dictionary just like that.
dict = {'name':'Tanvir','Position':'Programmer'};
print dict['name'];
if i run the code then there showing a syntax error.same thing is happening for the list also.
Please help me to fix the problem.
Thanks in advance.
In Python 3, print is a function, so you need print(dict[name]). You also don't need the semicolons. You also need to read the Python tutorial to learn the basics first.

Categories

Resources