iArray=range(5)
for x in range(5):
iArray[x]=0
iArray=range(5)
for x in range(5):
iArray[x]=x
for x in range(5):
print "The value of iArray index "+str(x)+"is "+str(x)
iIndex = -1
iArray=range(5)
for x in range(5):
iArray[x]=(x+5)
while (iIndex < 0 or iIndex >4):
iIndex=int(raw_input("Enter a valid index (0-4): "))
print "The value of index "+str(iIndex)+" is "+str(iArray[iIndex])
cArray = range(5)
cName="Olivia"
print "\nCharacter array not initialized:\n"
for x in range(5):
print "Element "+str(x)+"'s Contents are ",cArray[x]
print "\nInitialized character array: "
for x in range(6):
print cName[x],
iFound = -1
iArray=range(5)
for x in range(5):
iArray[x]=(x+x)
iValue=int(raw_input("Enter value to search for: "))
for x in range(5):
if (iArray[x]==iValue):
iFound=x
break
if(iFound > -1):
print "I found your search value in element ",iFound
else:
print "Sorry, your search value was not found"
iTwoD=[[0 for j in range(3)]for i in range(3)]
for x in range(3):
for y in range(3):
iTwoD[x][y]=(x+y)
for x in range(3):
for y in range(3):
print "iTwoD["+str(x)+"]["+str(y)+"]=",iTwoD[x][y]
iTwoD=[[1,2,3],[4,5,6],[7,8,9]]
iFoundAt=[0,0]
iValue=0
iFound=0
iValue=int(raw_input("Enter your search value: "))
for x in range(3):
for y in range(3):
if(iTwoD[x][y]==iValue):
iFound=1
iFoundAt[0]=x
iFoundAt[1]=y
break
if (iFound==1):
print "Found value in iTwoD ["+str(iFoundAt[0])+"]["+str(iFoundAt[1])+"]"
else:
print "Value not found"
board=range(9)
cWhoWon=' '
iCurrentPlayer=0
def displayBoard():
print "\n\t|\t|\n"
print "\t|\t|\n"
print ""+str(board[0])+"\t|"+str(board[1])+"\t|"+str(board[2])+"\n"
print "--------|-------|--------\n"
print ""+str(board[3])+"\t|"+str(board[4])+"\t|"+str(board[5])+"\n"
print "--------|-------|--------\n"
print "\t|\t|\n"
print ""+str(board[6])+"\t|"+str(board[7])+"\t|"+str(board[8])+"\n"
print "\t|\t|\n"
def verifySelection(iSquare,iPlayer):
if(board[iSquare-1]==' ' and (iPlayer==1 or iPlayer==0)):
board[iSquare-1]='X'
return 0
elif(board[iSquare-1]==' ' and iPlayer==2):
board[iSquare-1]='0'
return 0
else:
return 1
def checkForWin():
global cWhoWon
if(board[0]=='X' and board[1]=='X' and board[2]=='X'):
cWhoWon='X'
elif(board[3]=='X' and board[4]=='X' and board[5]=='X'):
cWhoWon='X'
elif(board[6]=='X' and board[7]=='X' and board[8]=='X'):
cWhoWon='X'
elif(board[0]=='X' and board[3]=='X' and board[6]=='X'):
cWhoWon='X'
elif(board[1]=='X' and board[4]=='X' and board[7]=='X'):
cWhoWon='X'
elif(board[2]=='X' and board[5]=='X' and board[8]=='X'):
cWhoWon='X'
elif(board[0]=='X' and board[5]=='X' and board[8]=='X'):
cWhoWon='X'
elif(board[2]=='X' and board[5]=='X' and board[6]=='X'):
cWhoWon='X'
elif(board[0]=='0' and board[1]=='0' and board[2]=='0'):
cWhoWon='0'
elif(board[3]=='0' and board[4]=='0' and board[5]=='0'):
cWhoWon='0'
elif(board[6]=='0' and board[7]=='0' and board[8]=='0'):
cWhoWon='0'
elif(board[0]=='0' and board[3]=='0' and board[6]=='0'):
cWhoWon='0'
elif(board[1]=='0' and board[4]=='0' and board[7]=='0'):
cWhoWon='0'
elif(board[2]=='0' and board[5]=='0' and board[8]=='0'):
cWhoWon='0'
elif(board[0]=='0' and board[5]=='0' and board[8]=='0'):
cWhoWon='0'
elif(board[2]=='0' and board[5]=='0' and board[6]=='0'):
cWhoWon='0'
if(cWhoWon!=' '):
if(cWhoWon=='X'):
print "\nX Wins!\n"
return
if(cWhoWon=='0'):
print "\n0 Wins!\n"
return
else:
return
for x in range(9):
if(board[x]!=' '):
catTotal=catTotal+1
if(catTotal==9):
cWhoWon='C'
print "\nCAT Game!\n"
return
iSquareNum=0
for x in range(8):
board[x]=' '
displayBoard()
while(cWhoWon==' '):
print "\n"+cWhoWon+"\n"
if(iCurrentPlayer==1 or iCurrentPlayer==0):
print "\nPLAYER X\n"
iSquareNum=int(raw_input("Enter an available square number (1-9): "))
if(verifySelection(iSquareNum,iCurrentPlayer)==1):
iCurrentPlayer=1
else:
iCurrentPlayer=2
else:
print "\nPLAYER 0\n"
iSquareNum=int(raw_input("Enter an available square number (1-9): "))
if(verifySelection(iSquareNum,iCurrentPlayer)==1):
iCurrentPlayer=2
else:
iCurrentPlayer=1
displayBoard()
checkForWin()