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
Every time I try to run these first 2 lines in python, it says:
SyntaxError: invalid syntax
And highlights the name of the variable I'm trying to define (Yname).
These are the lines I'm trying to run:
print("Hello what's your name?")\
Yname = input("your name:")
It is because of the \ at the end of the first line.
in Python \ is the line continuation character. Python is trying to parse this as
print("Hello what's your name?")Yname = input("your name:")
Related
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 am new here learning Python. I have a problem of syntax but I am unable to fix it. Can someone please help ?
Here's the code:
def saisie(the_list)
input_string = input("Enter a list elements separated by space (max 6)\n")
the_list = input_string.split()
if len(the_list) > 6:
return '{}Error'
return '{}Error'
else:
return f'user list: {the_list}'
saisie(liste)
and I got this error :
File "c:/Users/Jay/Desktop/Python Exercices/app/tribulle.py", line 6
def saisie(the_list)
^
SyntaxError: invalid syntax
Which is the invalid syntax, what should I change please?
When defining a function, you must put a colon at the end of the "def saisie(the_list)" or else Python will not know that you are defining a function.
You are missing the colon, it should be
def saisie(the_list):
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
I am trying to use machine learning to predict students' future grade, but am stuck at the beginning.
Seems like pandas.read_csv cannot read psv file, I got:
df = pd.read_csv(‘training.psv’)
^
SyntaxError: invalid character in identifier
How can I read psv file through python?
The problem is in the quotes symbol. You should either use ' or ".
Try:
df = pd.read_csv('training.psv')
pd.read_csv("training.psv", sep = "|", header = FALSE, stringsAsFactors = FALSE)
That should work
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 6 years ago.
Improve this question
So, I'm trying to make an easter egg in my calculator program, where if you type my friend johns name in, it prints nerd, but I keep getting invalid syntax on the line the if statement starts. here's what the code looks like:
x = input(' ')
if x = John:
print nerd
else:
print x
please keep in mind i'm using python 2.7, not 3. when I googled it, I only got answers that worked in 3.
x = raw_input('enter name ')
if x == 'John':
print 'nerd'
else:
print x
You are doing an assignment, but you need == to check for equality
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
A problem exists in Python 2.7.11, with the print function:
elif e=="randomize w and x":
random=randint(int(w),int(x))
print random
elif e=="randomize w and y":
random=randint(int(w,int(y))
print random
The boldfaced print shows up as a syntax error, yet all 278 others in my program do not. Why this is, and how I fix it?
The problem is that in
random=randint(int(w,int(y))
a close parenthesis after w is missing, therefore Python thinks the expression continues on next line, but print at that point is a syntax error.
Your problem is not with the print statement, rather the line right before it. The line before hass inbalanced parenthesis:
random=randint(int(w,int(y))
Make sure you balance them out (add an extra ) at the end), and your error on the next line will disappear.
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
I've got this piece of code that is a part of a student database I'm making for class and I really can't determine why I'm getting invalid syntax on a particular line (line 3, userints).
def userints():
choices = int(input("Choose Student ID 1-6:")
userints = int(choices)
print (userints)
if userints == 1:
for line_number, line in enumerate(fileinput.input('init2.txt', inplace=1)):
if line_number == 1:
continue
else:
sys.stdout.write(line)
You forgot about second brace.
You forgot a ) on the previous line. It should be:
choices = int(input("Choose Student ID 1-6:"))