Python - List function inserting values invalid syntax [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 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):

Related

i don't know how to fix this error, python3 syntax error 'def' [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
I want to solve this error.
i tried for almost half hours, but I couldn't find the answer..
This is my error
File "sampling_fun.py", line 71
def average(self) :
^
SyntaxError: invalid syntax
and full code
import csv
class fun :
def __init__(self, rowList, num) :
list = []
listLen = len(self.rowlist)-1
for i in range(listLen) :
list.append(self.rowList[i+1][num] # num = Header 1~4
def average(self) :
ave = sum(self.list)/self.lestLen
print("average : %0.2f" %ave)
return ave
testlist = cssRead('Data_2', 1)
test1 = fun(testlist, 1)
test1.average()
When you encounter such error, check the line before it.
You have a non-matching paranthesis, the closing brace for append is missing.
list.append(self.rowList[i+1][num])
def errors happen when python is not expecting a function definition. As #Siong Thye Goh notes, a missing ) is your issue. For the future, the only time python does not expect a function definition is after an incomplete code-block.
That can happen when you forget to close parentheses or brackets, but also when you forget to put a statement after a colon or don't indent correctly.
Rarely, it can happen due to incompatible space characters when copy-pasting from external sources.

If statement checking if a variable is equal to a specific word is getting 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 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

broken print feature in python 2.7.11 [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
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.

Python indentation error in if statement [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
I have a following trouble in Python.
sister_age = 15
brother_age = 12
if sisiter_age > brother_age:
print "sisiter is older"
else:
Error:
SyntaxError: invalid syntax
if sisiter_age > brother_age:
print "sisiter is older"
else:
File "<pyshell#5>", line 4
else:
^
IndentationError: unindent does not match any outer indentation level
No matter how many times I try to change the index, it shows an error.
Assuming there is something after the else statement, the else statement should be aligned with the if statement, not inside it.
Example -
if sisiter_age > brother_age:
print "sisiter is older"
else:
Also, if you do not have (or need) anything inside the else statement, you should just remove it.

I am not able to run this Python program [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
import random
for i in range(1,21):
print("%10d" %(random.randrange(1,7)),
if (i % 5 == 0):
print ("")
What is wrong in this code ?
I know basic python (almost), but i am not able to figure out what could be error in this program.
it is showing this error:
Syntax Error: invalid syntax at line 6 (if statement)
The fourth line is missing bracket .. Thanks all of you
You missed a right bracket )
print("%10d" %(random.randrange(1,7))),
would be correct
You're missing a ) before the last comma on line 4.
Your parenthesis on line 4 don't match. Because you have an unclosed paren, python doesn't report this syntax error until the colon on line 6 (python ignores line breaks as long as you are inside an enclosing set of parenthesis, brackets, or braces).

Categories