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.
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 4 years ago.
Improve this question
Any ideas why this line isn't working? I want a variable to be assigned the integer of the text in a label. If the label does not have any text assigned, I want the variable to equal 0.
I'm getting a "can't assign to conditional expression" error before it even tries to run.
var = int(label.cget("text")) if label.cget("text") != "" else var = 0
More pythonic:
var = int(label.cget("text") or 0)
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 7 years ago.
Improve this question
I'm trying to make a simple console game in Python 2.7, where the user gets a dilemma and makes a decision by typing the number correlating to the option he wants to choose. This question is the main menu.
s = raw_input("Enter a number in the range 1 to %s\n> " % v
if (is_number(s) and s in q):
return s
I'm getting a "SyntaxError: Invalid syntax" from the if (is_number(s) and s in q) statemet when trying to run the program. It was working fine before i added the question.
This is my first real program.
You're missing a parentheses on the previous line:
s = raw_input("Enter a number in the range 1 to %s\n> " % v
# here--^