-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHead Tail Dottless.py
120 lines (108 loc) · 3.43 KB
/
Head Tail Dottless.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# Head_tail game
import time
import random
score_list=[1,2,3,4,5,6]
bat_ball=["batting","balling"]
def start():
print("Hey I am computer8.08. But you can call me comp.")
print("I am not interested in this class. So I want to play head_tails.")
answer=input("Do you want to play with me?(yes/no): ")
if answer=="yes":
print("Great.\n")
print("Its a T20 game. So, I think you know the rules.\n")
toss()
print("Thanks for playing this game")
time.sleep(2)
print("Creator -->Ahammad Shawki")
time.sleep(4.5)
else:
print("Okay then I will play with Shawki.")
time.sleep(3)
def toss():
player_toss=input("heads or tails?\n")
player_num=int(input("player toss: "))
comp_number=random.choice(score_list)
print("comp toss:",comp_number)
if (player_num+comp_number)%2==0:
real_toss="tails"
else:
real_toss="heads"
print()
if player_toss==real_toss:
print("congrats you won the toss!")
section=input("batting or balling?\n")
else:
print("sorry you lost the toss:(")
section=random.choice(bat_ball)
if section=="batting":
print("you are going to bat first")
bat_part(section)
else:
print("you are going to ball first")
ball_part(section)
print()
def bat_part(section,comp_total=None):
out=False
player_total=0
while not out:
run=int(input("player bat: "))
ball=random.choice(score_list)
print("comp ball:",ball)
if run in score_list:
if run==ball:
print("out")
out=True
print("your total run",player_total)
else:
player_total+=run
if comp_total:
if comp_total<player_total:
print("your total run",player_total)
print("you won")
time.sleep(3.5)
break
if out:
if comp_total>player_total:
print("you lost")
elif comp_total==player_total:
print("Match drawn")
time.sleep(3.5)
else:
print("please pay a valid shot")
print()
if section=="batting":
print("now you are balling")
ball_part(section,player_total)
def ball_part(section,player_total=None):
out=False
comp_total=0
while not out:
run=random.choice(score_list)
ball=int(input("player ball: "))
print("comp bat:",run)
if ball in score_list:
if run==ball:
print("out")
out=True
print("comp's total run",comp_total)
else:
comp_total+=run
if player_total:
if comp_total>player_total:
print("comp's total run",comp_total)
print("you lost")
time.sleep(3.5)
break
if out:
if comp_total<player_total:
print("you won")
elif comp_total==player_total:
print("Match drawn")
time.sleep(3.5)
else:
print("please throw a valid ball")
print()
if section=="balling":
print("now you are batting")
bat_part(section,comp_total)
start()