It keeps giving me this elif syntax error in line 103 and I have NO idea where it's coming from. UGH!!!

``````#!/usr/bin/python

import os.path

#nxn board, in this case n = 10
n = 10
#will hold the positions similar to n-queens
allPositions = []
#current state of board used for comparisons
state = []
#defining captured and inaRow
blackPairCap = 0
whitePairCap = 0
blackInaRow = 0
whiteInaRow = 0

#the initial state of the board is all blank
#im storing each row of the board as a list
#this is pretty much only for displaying the board
row0 = []
row1 = []
row2 = []
row3 = []
row4 = []
row5 = []
row6 = []
row7 = []
row8 = []
row9 = []

#similar to the n-queens problem,
#i'll make an allDirections list so i can test later for things such as
#if it's next to another piece of itself or the opponent
allDirections = [[-1, 0],[1, 0],[0, -1],[0, 1],[-1, -1],[-1, 1],[1, -1],[1, 1]]

#creating all rules without precond or anything
def createPositions():
for i in range(0,n):
for j in range(0,n):
allPositions.append([i,j])

#winner
def winner():
if (blackPairCap == 5):
print "White is the winner!"
return True
elif (whitePairCap == 5):
print "Black is the winner!"
return True
elif (blackInaRow >= 5):
print "Black is the winner!"
return True
elif (whiteInaRow >= 5):
print "White is the winner!"
return True
else:

#for next function
player1 = ""
player2 = ""
comp1 = ""
comp2 = ""
#current players
currentPlayers = []

#save files list
FILES = []

print "Do you have a save file that you would like to run the game from?\n"
saveFile = raw_input("y or n")
saveFile = str(saveFile)
if saveFile == "y":
fileName = raw_input("What is the name of the save file (with extension)? \n")
FILES.append(fileName)
f = open(fileName, 'r')
for line in f:
if line == 0:
row0.extend([line,line,line,line,line,line,line,line,line,line])
if line == 1:
row0.extend([line,line,line,line,line,line,line,line,line,line])
if line == 2:
row0.extend([line,line,line,line,line,line,line,line,line,line])
if line == 3:
row0.extend([line,line,line,line,line,line,line,line,line,line])
if line == 4:
row0.extend([line,line,line,line,line,line,line,line,line,line])
if line == 5:
row0.extend([line,line,line,line,line,line,line,line,line,line])
if line == 6:
row0.extend([line,line,line,line,line,line,line,line,line,line])
if line == 7:
row0.extend([line,line,line,line,line,line,line,line,line,line])
if line == 8:
row0.extend([line,line,line,line,line,line,line,line,line,line])
if line == 9:
row0.extend([line,line,line,line,line,line,line,line,line,line])
f.close()

elif saveFile == "n":
print "Welcome to Pente!\n"
print "Would you like to play a new game?\n"
numPlayers = raw_input("How many players are going to be playing? (1-4):\n")
numPlayers = int(numPlayers)
for p in range(0,numPlayers):
print "Would you like to be Player 1, Player 2, PC 1, or PC 2?\n"
player = raw_input("p1, p2, pc1, or pc2:")
player = str(player)
if (player == "p1"):
currentPlayers.append(player1)
elif (player == "p2"):
currentPlayers.append(player2)
elif (player == "pc1"):
currentPlayers.append(comp1)
elif (player == "pc2"):
currentPlayers.append(comp2)

print "Which color would you like to play as?\n"
color = raw_input("b (black) or w (white):")
color = str(color)
if (color == "b"):
currentPlayers[p] = "black"
elif (color == "w"):
currentPlayers[p] = "white"

#defining players and their colors

return

def saveFileGame():
return

## All 5 Replies

`elif` and `else` must have the same indentation than the corresponding `if` .
Edit: sorry, in your code, the 2 lines before the elif should be indented like the for statement above.

Ok I restructured things around a little bit and that first elif error went away but now I have another one!!!

``````#!/usr/bin/python

import os.path

#nxn board, in this case n = 10
n = 10
#will hold the positions similar to n-queens
allPositions = []
#current state of board used for comparisons
state = []
#defining captured and inaRow
blackPairCap = 0
whitePairCap = 0
blackInaRow = 0
whiteInaRow = 0

#the initial state of the board is all blank
#im storing each row of the board as a list
#this is pretty much only for displaying the board
row0 = []
row1 = []
row2 = []
row3 = []
row4 = []
row5 = []
row6 = []
row7 = []
row8 = []
row9 = []

#similar to the n-queens problem,
#i'll make an allDirections list so i can test later for things such as
#if it's next to another piece of itself or the opponent
allDirections = [[-1, 0],[1, 0],[0, -1],[0, 1],[-1, -1],[-1, 1],[1, -1],[1, 1]]

#creating all rules without precond or anything
def createPositions():
for i in range(0,n):
for j in range(0,n):
allPositions.append([i,j])

#winner
def winner():
if (blackPairCap == 5):
print "White is the winner!"
return True
elif (whitePairCap == 5):
print "Black is the winner!"
return True
elif (blackInaRow >= 5):
print "Black is the winner!"
return True
elif (whiteInaRow >= 5):
print "White is the winner!"
return True
else:

#for next function
player1 = ""
player2 = ""
comp1 = ""
comp2 = ""
#current players
currentPlayers = []

#save files list
FILES = []

print "Do you have a save file that you would like to run the game from?\n"
saveFile = raw_input("y or n")
saveFile = str(saveFile)
if saveFile == "y":
saveFileGame()
elif saveFile == "n":
newGame()

#defining players and their colors

return

#new game
def newGame():
print "Welcome to Pente!\n"
print "Would you like to play a new game?\n"
numPlayers = raw_input("How many players are going to be playing? (1-4):\n")
numPlayers = int(numPlayers)
for p in range(0,numPlayers):
print "Would you like to be Player 1, Player 2, PC 1, or PC 2?\n"
player = raw_input("p1, p2, pc1, or pc2:")
player = str(player)
if (player == "p1"):
currentPlayers.append(player1)
elif (player == "p2"):
currentPlayers.append(player2)
elif (player == "pc1"):
currentPlayers.append(comp1)
elif (player == "pc2"):
currentPlayers.append(comp2)
print "Which color would you like to play as?\n"
color = raw_input("b (black) or w (white):")
color = str(color)
if (color == "b"):
currentPlayers[p] = "black"
elif (color == "w"):
currentPlayers[p] = "white"

def saveFileGame():
fileName = raw_input("What is the name of the save file (with extension)? \n")
FILES.append(fileName)
f = open(fileName, 'r')
for line in f:
if line == 0:
row0.extend([line,line,line,line,line,line,line,line,line,line])
if line == 1:
row0.extend([line,line,line,line,line,line,line,line,line,line])
if line == 2:
row0.extend([line,line,line,line,line,line,line,line,line,line])
if line == 3:
row0.extend([line,line,line,line,line,line,line,line,line,line])
if line == 4:
row0.extend([line,line,line,line,line,line,line,line,line,line])
if line == 5:
row0.extend([line,line,line,line,line,line,line,line,line,line])
if line == 6:
row0.extend([line,line,line,line,line,line,line,line,line,line])
if line == 7:
row0.extend([line,line,line,line,line,line,line,line,line,line])
if line == 8:
row0.extend([line,line,line,line,line,line,line,line,line,line])
if line == 9:
row0.extend([line,line,line,line,line,line,line,line,line,line])
f.close()

This one is in line 101

lines 101 - 106 need to lose a tab, i.e., un-indent each of those lines once.

I did that and now there's another error in line 102 (lines switched around cuz I kinda reformatted the whole thing). Ugh I hate these elif errors!

``````#!/usr/bin/python

import os.path

#nxn board, in this case n = 10

n = 10

#will hold the positions similar to n-queens

allPositions = []

#current state of board used for comparisons

state = []

#defining captured and inaRow

blackPairCap = 0

whitePairCap = 0

blackInaRow = 0

whiteInaRow = 0

#the initial state of the board is all blank

#im storing each row of the board as a list

#this is pretty much only for displaying the board

row0 = []

row1 = []

row2 = []

row3 = []

row4 = []

row5 = []

row6 = []

row7 = []

row8 = []

row9 = []

#similar to the n-queens problem,

#i'll make an allDirections list so i can test later for things such as

#if it's next to another piece of itself or the opponent

allDirections = [[-1, 0],[1, 0],[0, -1],[0, 1],[-1, -1],[-1, 1],[1, -1],[1, 1]]

#creating all rules without precond or anything

def createPositions():

for i in range(0,n):

for j in range(0,n):

allPositions.append([i,j])

#winner

def winner():

if (blackPairCap == 5):

print "White is the winner!"

return True

elif (whitePairCap == 5):

print "Black is the winner!"

return True

elif (blackInaRow >= 5):

print "Black is the winner!"

return True

elif (whiteInaRow >= 5):

print "White is the winner!"

return True

else:

#for next function

player1 = ""

player2 = ""

comp1 = ""

comp2 = ""

#current players

currentPlayers = []

#save files list

FILES = []

print "Do you have a save file that you would like to run the game from?\n"

saveFile = raw_input("y or n")

saveFile = str(saveFile)

if saveFile == "y":

fileName = raw_input("What is the name of the save file (with extension)? \n")

FILES.append(fileName)

f = open(fileName, 'r')

for line in f:

if line == 0:

row0.extend([line,line,line,line,line,line,line,line,line,line])

if line == 1:

row0.extend([line,line,line,line,line,line,line,line,line,line])

if line == 2:

row0.extend([line,line,line,line,line,line,line,line,line,line])

if line == 3:

row0.extend([line,line,line,line,line,line,line,line,line,line])

if line == 4:

row0.extend([line,line,line,line,line,line,line,line,line,line])

if line == 5:

row0.extend([line,line,line,line,line,line,line,line,line,line])

if line == 6:

row0.extend([line,line,line,line,line,line,line,line,line,line])

if line == 7:

row0.extend([line,line,line,line,line,line,line,line,line,line])

if line == 8:

row0.extend([line,line,line,line,line,line,line,line,line,line])

if line == 9:

row0.extend([line,line,line,line,line,line,line,line,line,line])

f.close()

elif saveFile == "n":

newGame()

#defining players and their colors

return

def saveFileGame():

return

#newGame

def newGame():

print "Welcome to Pente!\n"

print "Would you like to play a new game?\n"

numPlayers = raw_input("How many players are going to be playing? (1-4):\n")

numPlayers = int(numPlayers)

for p in range(0,numPlayers):

print "Would you like to be Player 1, Player 2, PC 1, or PC 2?\n"

player = raw_input("p1, p2, pc1, or pc2:")

player = str(player)

if (player == "p1"):

currentPlayers.append(player1)

elif (player == "p2"):

currentPlayers.append(player2)

elif (player == "pc1"):

currentPlayers.append(comp1)

elif (player == "pc2"):

currentPlayers.append(comp2)

print "Which color would you like to play as?\n"

color = raw_input("b (black) or w (white):")

color = str(color)

if (color == "b"):

currentPlayers[p] = "black"

elif (color == "w"):

currentPlayers[p] = "white"

don't mind the double spacing, idk why it did that, it's not like that in my editor

Ugh I hate these elif errors!

Then don't use it. Some examples that also simplify the code.

``````## instead of if line == 0 ,1 2, etc.
for line in f:
if (line > -1) and (line < 10):
row0.extend([line[x] for x in range (0, 10)])
##
##------------------------------------------------------------------
"""
#the initial state of the board is all blank
#im storing each row of the board as a list
#this is pretty much only for displaying the board

row0 = []
row1 = []
row2 = []
row3 = []
row4 = []
row5 = []
row6 = []
row7 = []
row8 = []
row9 = []
"""
## use a list of lists or a dictionary instead
## this is a dictionary with the key = 0 --> 9 instead
## of row0 --> row9
row_dic = {}
for j in range(0, 10):
row_dic[j] = []
##
##------------------------------------------------------------------
elif (player == "p2"):, etc.
"""
player_dic = {}
player_dic["p1"] = player1
player_dic["p2"] = player2
player_dic["pc1"] = comp1
player_dic["pc2"] = comp2
for p in range(0,numPlayers):

print "Would you like to be Player 1, Player 2, PC 1, or PC 2?\n"
player = raw_input("p1, p2, pc1, or pc2:")
player = player.lower()
if (player in player_dic):
currentPlayers.append( player_dic[player] )
else:
print "That is not a valid player"``````

Hopefully you get the idea.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.