# First "If" Enemy Selection Function being recognized as a syntax error in Python

I have an issue with trying to under the syntax error with the line if enemy_select = 1: in this type of code:

enemy_select = random.randit(1, 11)

for enemy_select in range(1):
if enemy_select = 1:
enemy_type = character 1

elif enemy_select = 2:
enemy_type = character 2

elif enemy_select = 3:
enemy_type = character 3

elif enemy_select = 4:
enemy_type = character 4

elif enemy_select = 5:
enemy_type = character 5

elif enemy_select = 6:
enemy_type = character 6

elif enemy_select = 7:
enemy_type = character 7

elif enemy_select = 8:
enemy_type = character 8

elif enemy_select = 10:
enemy_type = character 9

elif enemy_select = 10:
enemy_type = character 10

elif enemy_select = 11:
enemy_type = character 11

• What exactly does the syntax error say? Jul 26, 2018 at 13:39
• It just returns it as an invalid syntax Jul 26, 2018 at 13:41
• In the future, please try to reduce the problem before posting code - if all the trail elifs aren't part of the problem (i.e. problem remains unchanged after removing them), don't include them. Short, easy to read code is more likely to get get answers & often you resolve the issue on your own when narrowing it down. Jul 26, 2018 at 15:13

It seems you lack the correct indentation for all your lines after for....

Add few spaces or tab at the beginning of every line, starting from first if.

EDIT:

I was wrong, the problem is that you're using = instead of == in if lines.

BTW: I've tried it in CMD window and it has shown me a ^ sign at the exact character that caused an error. May be helpful in the future.

• Even after tabbing every line (Starting from 'if') it still says that there is a syntax error. Not to mention that wouldn't it give an indentation error if the indentation was incorrect? Jul 26, 2018 at 14:18
• I've updated my answer. Jul 26, 2018 at 14:43
• I'm not that familiar with Python, even though = instead of == is an error, wouldn't that be a logic error? As in the compiler can't catch it no matter what? At least that's the case in C. Jul 26, 2018 at 15:16
• In C you can write if( i=1 ) and it compiles but C allows you to do a lot of such things. Python seems to be more restrictive and assignment operation is not the one he expects in an if statement, so it throws a generic "syntax error". I still agree that the message could be better. Jul 27, 2018 at 8:51
• Tried to fix it, just gave some generic "indentation error" or just replies a syntax error at the end of the code Jul 27, 2018 at 19:55