Apparently, the “:” on my if statement is invalid syntax [closed]

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)
             

Answer

The problem is the stray ‘(‘ you have before random.choice([team1, team2]). Delete it so it becomes:

rand = random.choice([team1, team2])

Leave a Reply

Your email address will not be published. Required fields are marked *