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 am running Python 2.7.6 and when I execute the following if statement works. But if I add the commented out elif line I get a syntax error. any ideas
if output == 0:
print(Num,"is Even")
# elif output = 0:
# print(Num,"is Odd" )
else:
print (Num,"is Odd")
You want output==0 in the elif, which is comparison as opposed to output=0 (which is assignment)
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 1 year ago.
Improve this question
I am currently trying to create team selection code for my python video game.
Unfortunately, it keeps highliting the ":" of my if statement and saying that it is invalid syntax, even if i change the if statement for another. I tried everything, but after all, it IS an if statement, and i can't do much.
Heres my minimal recreation of the problem. The structure is important as there is netwroking code there;
team1=[]
team2=[]
if (len(team1)+len(team2)):
if team1==team2:
rand = (random.choice([team1, team2])
if rand == "team1":
team1.append(username)
else:
team2.append(username)
else:
if team1>=team2:
team1.append(username)
else:
team2.append(username)
else:
team1.append(username)
The problem is the stray '(' you have before random.choice([team1, team2]). Delete it so it becomes:
rand = random.choice([team1, team2])
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
Whats wrong with my If statement?
if (current_value_address == current_value['address'] and
current_input['xy'] >= current_required_value and
current_xy_amount >= MIN_AMO and
AFFL_COME > 1):
getaf_id = db.cursor()
Error:
getaf_id = db.cursor()
IndentationError: expected an indented block
If i remove the If statement it works.
You only need to indent that last part:
if (current_value_address == current_value['address'] and
current_input['xy'] >= current_required_value and
current_xy_amount >= MIN_AMO and
AFFL_COME > 1):
getaf_id = db.cursor(). #indent this line!
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 5 years ago.
Improve this question
def mystrcmp(x,y):
print (x.lower(),y.lower())
if(str(x.lower()) == str(y.lower())):
print ("true")
else:
print ("false")
mystrcmp("python", "pTHYON")
This code gives incorrect output, it should give True but gives False
i solved it, spelling mistake, Python
You Can Use the following script to really get a true output
def mystrcmp(x,y):
x, y = str(x),str(y)
print(x.lower(),y.lower())
if x.lower() == y.lower():
print ("true")
else:
print ("false")
mystrcmp("python", "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 5 years ago.
Improve this question
I am new to python and trying to execute my code. Below is my code.
def evod(number):
if number % 2 == 0:
print("The number is even")
return"The number is odd"
print(evod(60))
Output is:
The number is even
The number is odd
if I run this function it prints both lines. It should print a single one of those. Right? Why is this happening?
if c=="July":
print("7/1/2017")
else:
print("sorry")
Indentation matters in python!
if c == "July":
print ("7/1/2017")
else:
print ("sorry")
Correct your indentation
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
Issue occurred right after I added the and x= "J1234": I don't know what's going on.
original = ""
if len(original) > 0 and x = "J123":
raw_input("Enter a word:")
original = raw_input('word')
print "original"
else:
print "empty"
x.isalpha()
So, you're getting a SyntaxError. To fix this, change:
x = "J123":
to...
x == "J123":
In Python the former is for setting values and the latter is for checking them. Therefore when you use this the wrong way round the syntax is incorrect.