Home > other >  Why don't the python if statement execution
Why don't the python if statement execution

Time:11-16

# drawing board
The TBP={' a1 ':', 'a2' : ', 'a3' : ', 'b1' : ', 'b2' : ', 'b3' : ', 'c1' : ', 'c2' : ', 'c3' : '}
Def cb (board) :
Print (board [' a1] + '|' + board/' a2 '+' | '+ board [' a3'])
Print (' -- -- -- -- -- - ')
Print (board [' b1] + '|' + board [' b2] + '|' + board [' b3 '])
Print (' -- -- -- -- -- - ')
Print (board [' c1] + '|' + board [' c2] + '|' + board [' c3])
# judgment winning
Def aqw (the TBP) :
# dicts=dict (the TBP)
If (the TBP [' a1]==the TBP [' a2 '] and the TBP [' a2 ']==the TBP [' a3] and the TBP [' a3]!=' ') :
If (the TBP [' a1]=='x') :
Print (' game over, '+' players win x ')
Return 1
The else:
Print (' game over, '+' players to win o ')
Return 2
Elif (the TBP [' a1]==the TBP [' b2] and the TBP [' b2]==the TBP [' c3] and the TBP [' a3]!=' ') :
If (the TBP [' a1]=='x') :
Print (' game over, '+' players win x ')
Return 1
The else:
Print (' game over, '+' players to win O ')
Return 2
Elif (the TBP [' a1]==the TBP [' b1] and the TBP [' b1]==the TBP [' c1] and the TBP [' a3]!=' ') :
If (the TBP [' a1]=='x') :
Print (' game over, '+' players win x ')
Return 1
The else:
Print (' game over, '+' players to win O ')
Return 2
Elif (the TBP [' a2 ']==the TBP [' b2] and the TBP [' b2]==the TBP [' c2] and the TBP [' a3]!=' ') :
If (the TBP [' a2 ']=='x') :
Print (' game over, '+' players win x ')
Return 1
The else:
Print (' game over, '+' players to win O ')
Return 2
Elif (the TBP [' a3]==the TBP [' b3 '] and the TBP [' b3]==the TBP [' c3] and the TBP [' a3]!=' ') :
If (the TBP [' a3]=='x') :
Print (' game over, '+' players win x ')
Return 1
The else:
Print (' game over, '+' players to win O ')
Return 2
Elif (the TBP [' a3]==the TBP [' b2] and the TBP [' b3]==the TBP [' c1] and the TBP [' a3]!=' ') :
If (the TBP [' a3]=='x') :
Print (' game over, '+' players win x ')
Return 1
The else:
Print (' game over, '+' players to win O ')
Return 2
Elif (the TBP [' b1]==the TBP [' b2] and the TBP [' b2]==the TBP [' b3 '] and the TBP [' a3]!=' ') :
If (the TBP [' b1]=='x') :
Print (' game over, '+' players win x ')
Return 1
The else:
Print (' game over, '+' players to win O ')
Return 2
Elif (the TBP [' c1]==the TBP [' c2] and the TBP [' c2]==the TBP [' c3] and the TBP [' a3]!=' ') :
If (the TBP [' c1]=='x') :
Print (' game over, '+' players win x ')
Return 1
The else:
Print (' game over, '+' players to win O ')
Return 2
The else:
Return 0
# chess operation
Turn='X'
For I in range (9) :

Print (' players: '+ +' please chess: 'turn, end=' ')
Move=input ()
The TBP [move]=turn
Cb (the TBP)
Awd=aqw (the TBP)
If awd> 0:
Break
# substitution operation
If (turn=='X') :
Turn='O'
The else:
Turn='X'
  • Related