| | |
elif error, i really have no clue where this is coming from
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: May 2008
Posts: 33
Reputation:
Solved Threads: 0
It keeps giving me this elif syntax error in line 103 and I have NO idea where it's coming from. UGH!!!
python Syntax (Toggle Plain Text)
#!/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: inGameMenu() #for next function player1 = "" player2 = "" comp1 = "" comp2 = "" #current players currentPlayers = [] #save files list FILES = [] #startGameMenu def startGameMenu(): 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[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 1: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 2: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 3: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 4: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 5: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 6: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 7: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 8: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 9: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) f.close() inGameMenu() elif saveFile == "n": print "Welcome to Pente!\n" print "Would you like to play a new game?\n" answer = raw_input("y or n:") answer = str(answer) if (answer == "y"): 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" inGameMenu() #defining players and their colors #inGameMenu def inGameMenu(): return #inGameMenu from save file def saveFileGame(): return #startGameMenu()
•
•
Join Date: May 2008
Posts: 33
Reputation:
Solved Threads: 0
Ok I restructured things around a little bit and that first elif error went away but now I have another one!!!
This one is in line 101
python Syntax (Toggle Plain Text)
#!/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: inGameMenu() #for next function player1 = "" player2 = "" comp1 = "" comp2 = "" #current players currentPlayers = [] #save files list FILES = [] #startGameMenu def startGameMenu(): 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 #inGameMenu def inGameMenu(): return #new game def newGame(): print "Welcome to Pente!\n" print "Would you like to play a new game?\n" answer = raw_input("y or n:") answer = str(answer) if (answer == "y"): 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" inGameMenu() #inGameMenu from save file 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[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 1: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 2: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 3: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 4: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 5: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 6: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 7: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 8: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 9: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) f.close() inGameMenu() #startGameMenu()
This one is in line 101
•
•
Join Date: May 2008
Posts: 33
Reputation:
Solved Threads: 0
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!
don't mind the double spacing, idk why it did that, it's not like that in my editor
python Syntax (Toggle Plain Text)
#!/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: inGameMenu() #for next function player1 = "" player2 = "" comp1 = "" comp2 = "" #current players currentPlayers = [] #save files list FILES = [] #startGameMenu def startGameMenu(): 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[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 1: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 2: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 3: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 4: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 5: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 6: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 7: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 8: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 9: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) f.close() inGameMenu() elif saveFile == "n": newGame() #defining players and their colors #inGameMenu def inGameMenu(): return #inGameMenu from save file def saveFileGame(): return #newGame def newGame(): print "Welcome to Pente!\n" print "Would you like to play a new game?\n" answer = raw_input("y or n:") answer = str(answer) if (answer == "y"): 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" inGameMenu() #startGameMenu()
don't mind the double spacing, idk why it did that, it's not like that in my editor
Last edited by gotm; May 17th, 2009 at 9:06 pm.
•
•
Join Date: Dec 2006
Posts: 1,022
Reputation:
Solved Threads: 287
•
•
•
•
Ugh I hate these elif errors!
Python Syntax (Toggle Plain Text)
## 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] = [] ## ##------------------------------------------------------------------ """ instead of 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"
![]() |
Similar Threads
- Active desktop recovery/Script error (Windows NT / 2000 / XP)
- HELP!! "couldn't load main class" error (Windows Software)
- error message on startup on xp - mfc71u.dll (Windows NT / 2000 / XP)
- windows xp pro stop error, happens after only a few minutes of loading up (Troubleshooting Dead Machines)
- How to Resolve "Server Error '/' Application" Message? (ASP.NET)
- error 1722 (Java)
- Computer keeps crashing- error code help plz (Windows NT / 2000 / XP)
- Fibonacci Problem Help!! (Python)
- What to do? Error message keeps coming up (Windows NT / 2000 / XP)
Other Threads in the Python Forum
- Previous Thread: CGI versus CherryPy ?
- Next Thread: how to avoid spaces in login and password fields
| Thread Tools | Search this Thread |
alarm ansi assignment avogadro backend beginner binary bluetooth character cmd code customdialog cx-freeze data decimals dictionary directory drive dynamic error examples exe file float format function gnu graphics gui halp heads homework http ideas import input itunes java leftmouse line linux list lists logging loop module mouse number numbers output parsing path pointer port prime programming progressbar projects push py2exe pygame pyglet pyqt python random recursion schedule screensaverloopinactive script scrolledtext sqlite ssh statistics stdout string strings sudokusolver sum table terminal text thread threading time tlapse tricks tuple tutorial ubuntu unicode urllib urllib2 variable ventrilo verify webservice wikipedia write wxpython xlib






