Answer to Question #336268 in Python for sandhya

Question #336268

TIC-TAC-TOE

ravan's dream is to win the tic-tac-toe champions to accomplish this,the practices alone at home to learn the strategies in the game your task is to identify the cell where ravan should place his 3rd piece so that be wins the game Assume that each cell in the tic-tac-toe board is marked with number as shown in the table below

tic tac toe

0 1 2

3 4 5

6 7 8

input:

the 1st line of input contains two space-separated integers represetation the cells where ravan has placed his 1st two piece

i/P:

0 1

o/P: 2

i/p: 0 3

o/p:6


1
Expert's answer
2022-05-04T17:39:52-0400
while True:

  s = input('Please, input two cells (numbers from 0 to 8) => ').strip()

  if s.find(' ') != -1:

    s = s.split()

    if len(s) == 2 and len(s[0]) == 1 and len(s[1]) == 1 and s[0].isdigit() == True and s[1].isdigit() == True:

      break

    else:

      print('Please, input two numbers from 0 - 8 inclusive')

  else:

    print('Please, input two numbers from 0 - 8 inclusive')




first, second = int(s[0]), int(s[1])




if second - first == 1 and second != 2 and second != 5 and second != 8:

  print(second + 1)

elif second - first == 1 and (second == 2 or second == 5 or second == 8):

  print(first - 1)

elif second - first == 3 and second != 6 and second != 7 and second != 8:

  print(second + 3)

elif second - first == 3 and (second == 6 or second == 7 or second == 8):

  print(first - 3)

elif second - first == 2:

  print(second - 1)

elif second - first == 6:

  print(second - 3)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS