forked from keshavsingh4522/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkj.py
103 lines (60 loc) · 1.83 KB
/
kj.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env python
# coding: utf-8
# In[1]:
def win(p,total):
print(total)
if (total[0]==total[1] and total[0]==total[2] and total[0]==p) or (total[3]==total[4] and total[3]==total[5] and total[3]==p) or (total[6]==total[7] and total[6]==total[8] and total[6]==p) or (total[0]==total[4] and total[0]==total[7] and total[0]==p) or (total[4]==total[8] and total[4]==total[2] and total[4]==p):
return True
else:
return False
# In[2]:
def grid(total):
print("{}|{}|{}".format(total[0],total[1],total[2]))
print("{}|{}|{}".format(total[3],total[4],total[5]))
print("{}|{}|{}".format(total[6],total[7],total[8]))
#grid()
# In[3]:
def main_game():
player2 = "l"
player1= input("enter your symbol- X/0--> ")
if player1 == "X":
player2 = "0"
elif player1== "0":
player2 = "X"
else:
player1= input("enter your symbol- X/0--> ")
print("player1 = " + player1 + " player2 = " + player2)
#game here
no_winner = True
total = [1,2,3,4,5,6,7,8,9]
grid(total)
while no_winner:
total[int(input("player1 -> enter position "))-1] = player1
grid(total)
if win(player1,total):
print("player1 won")
status =False
break
total[int(input("player2 -> enter position "))-1] = player2
grid(total)
if win(player2,total):
print("player1 won")
status =False
break
# In[4]:
def ask_replay():
reply = input("do you want to play again - y/n")
if reply == "y":
print("thanks for playing again")
play()
else:
print(" quitting the game")
# In[ ]:
def play():
main_game()
ask_replay()
# In[ ]:
play()
# In[ ]:
# In[ ]:
# In[ ]: