tanmoklepasha

tic-tac-toe

Oct 25th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.04 KB | None | 0 0
  1. a={"1":"1","2":"2","3":"3","4":"4","5":"5","6":"6","7":"7","8":"8","9":"9"}
  2. insert1=[]
  3. def PrintTable():
  4.     print("-------------")
  5.     print("|",a["1"],"|",a["2"],"|",a["3"],"|")
  6.     print("-------------")
  7.     print("|",a["4"],"|",a["5"],"|",a["6"],"|")
  8.     print("-------------")
  9.     print("|",a["7"],"|",a["8"],"|",a["9"],"|")
  10.     print("-------------")
  11.  
  12. def insert():
  13.     i=0
  14.     while True:
  15.         insertx(insert1)
  16.         PrintTable()
  17.         winx=win_X()
  18.         i+=1
  19.         if winx==9:
  20.             break
  21.         if i==9:
  22.             print("draw !!!!!!!!!!!!!!")
  23.             break
  24.  
  25.         inserto(insert1)
  26.         PrintTable()
  27.         wino=win_O()
  28.         i+=1
  29.         if wino==9:
  30.             break
  31.  
  32. def insertx(insert1):
  33.     b=input("enter x : ")
  34.     try:
  35.         if not(b in insert1):
  36.             insert1+=[b]
  37.             for c in a:
  38.                 if b==c:
  39.                     a[c]="X"
  40.         else:
  41.             1/0
  42.     except ZeroDivisionError :
  43.         print("This place is already valued")
  44.         insertx(insert1)
  45.  
  46. def inserto(insert1):
  47.     q=input("enter o : ")
  48.     try:
  49.         if not(q in insert1):
  50.             insert1+=[q]
  51.             for c in a:
  52.                 if q==c:
  53.                     a[c]="O"
  54.         else:
  55.             1/0
  56.     except ZeroDivisionError:
  57.         print("This place is already valued")
  58.         inserto(insert1)
  59.        
  60.  
  61.  
  62.         print("This place is already valued")
  63.        
  64. def win_X():
  65.     if a["1"]==a["2"]==a["3"] or a["4"]==a["5"]==a["6"] or a["7"]==a["8"]==a["9"] or a["1"]==a["4"]==a["7"] or a["2"]==a["5"]==a["8"] or a["3"]==a["6"]==a["9"] or a["1"]==a["5"]==a["9"] or a["3"]==a["5"]==a["7"]:
  66.         print("Win X !!!!!!!!!!!!!!")
  67.         return 9
  68. def win_O():
  69.     if a["1"]==a["2"]==a["3"] or a["4"]==a["5"]==a["6"] or a["7"]==a["8"]==a["9"] or a["1"]==a["4"]==a["7"] or a["2"]==a["5"]==a["8"] or a["3"]==a["6"]==a["9"] or a["1"]==a["5"]==a["9"] or a["3"]==a["5"]==a["7"]:
  70.         print("Win O !!!!!!!!!!!!!!")
  71.         return 9
  72.  
  73.  
  74.  
  75. PrintTable()
  76. insert()
Advertisement
Add Comment
Please, Sign In to add comment