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.
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 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
Consider following short Python program:
i= 21;
j= 23;
print (i);
if i>j :
print ('greater')
else :
print 'lesser'
It is giving the error
IndentationError: expected an indented block
What is the cause of this error? (I want to understand it better as I am new to Python.)
You need to indent statements that are intended to be in if-else blocks:
i = 21
j = 23
print (i)
if i > j:
print('greater')
else:
print('lesser')
Any time you have a colon, you follow it with an indented block of text. Everything in that block applies to the thing with the colon (which could be a function that you're defining, an if-statement, for-loop, etc). Indents should be 4 spaces (tabs also work).
Also, you don't need semicolons at the end of each line.
Example:
def function(parameter):
block line 1
block line 2
print function(argument)
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'm new to python so this may be a beginner question. My 'else' statement in the code below gets a syntax error for a reason beyond my mind. I've looked up the syntax for it multiple times but I cannot find the error. This is my python code:
siteswap = input("Enter the siteswap you want to validate here:")
aantal_digits = len(siteswap)
i = 0
j = 1
while i != aantal_digits:
if (int(siteswap[i])+ (i + 1)) % aantal_digits == (int(siteswap[1:aantal_digits])+ (j + 1)) % aantal_digits:
print("This siteswap is invalid")
break
elif i != aantal_digits:
del (int(siteswap[i])
else:
print ("This siteswap is valid")
break
The else is highlighted and I get a "syntax error".
Your problem is
del (int(siteswap[i])
You are missing a closing parenthesis (but the parenthesis are unnecessary in the first place). Also, del int(siteswap[i]) will not work, because you cannot delete function calls: SyntaxError: can't delete function call
del siteswap[i]
will delete the actual item from your array.
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).