Handcricket Code
Handcricket Code
import random
def you_firstbatting(t,b):
r=0
w =0
for loop in range(1,b+1,1):
n = int(input('enter your choice (1-6):'))
c = random.randint(1,6)
print('computer choice:',c)
if n == 1 or n <= 6:
if n == c:
w += 1
print('no.of wicket of your:',w)
if w == t:
break
else:
r += n
print('total runs:',r)
k = 99999999999
if k < r:
break
else:
print('Invalid choice')
print('you means zero run on this ball')
print(f'total runs of your:{r} and total wicket of your:{w}')
return r
def comp_firstbatting(t,b):
r1 = 0
w1 = 0
for loop in range(1,b+1,1):
q = int(input('enter your choice:'))
e = random.randint(1,6)
print('computer choice:',e)
if e == q:
w1 += 1
print('no.of wicket of computer:',w1)
if w1 == t:
break
else:
r1 += e
print('total run of computer:',r1)
o = 99999999999
if o < r1:
break
print(f'total runs for computer:{r1} and total wicket for computer:{w1}')
return r1
def you(t,b):
r=0
w =0
for loop in range(1,b+1,1):
n = int(input('enter your choice (1-6):'))
c = random.randint(1,6)
print('computer choice:',c)
if n >= 1 or n <= 6:
if n == c:
w += 1
print('no.of wicket of your:',w)
if w == t:
break
else:
r += n
print('total runs:',r)
global k
if k < r:
break
else:
print('Invalid choice')
print('you means zero run on this ball')
print(f'total runs of your:{r} and total wicket of your:{w}')
return r
def comp(t,b):
r1 = 0
w1 = 0
for loop in range(1,b+1,1):
q = int(input('enter your choice:'))
e = random.randint(1,6)
print('computer choice:',e)
if e == q:
w1 += 1
print('no.of wicket of computer:',w1)
if w1 == t:
break
else:
r1 += e
print('total run of computer:',r1)
global o
if o < r1:
break
print(f'total runs for computer:{r1} and total wicket for computer:{w1}')
return r1
def you_firstbatting1(t,b):
r=0
w =0
for loop in range(1,b+1,1):
n = int(input('enter your choice (1-10):'))
c = random.randint(1,10)
print('computer choice:',c)
if n == 1 or n <= 10:
if n == c:
w += 1
print('no.of wicket of your:',w)
if w == t:
break
else:
r += n
print('total runs:',r)
k = 99999999999
if k < r:
break
else:
print('Invalid choice')
print('you means zero run on this ball')
print(f'total runs of your:{r} and total wicket of your:{w}')
return r
def comp_firstbatting1(t,b):
r1 = 0
w1 = 0
for loop in range(1,b+1,1):
q = int(input('enter your choice:'))
e = random.randint(1,10)
print('computer choice:',e)
if e == q:
w1 += 1
print('no.of wicket of computer:',w1)
if w1 == t:
break
else:
r1 += e
print('total run of computer:',r1)
o = 99999999999
if o < r1:
break
print(f'total runs for computer:{r1} and total wicket for computer:{w1}')
return r1
def you1(t,b):
run = 0
w =0
for loop in range(1,b+1,1):
n = int(input('enter your choice (1-10):'))
c = random.randint(1,10)
print('computer choice:',c)
if n >= 1 or n <= 10:
if n == c:
w += 1
print('no.of wicket of your:',w)
if w == t:
break
else:
run += n
print('total runs:',run)
global r
if r < run:
break
else:
print('Invalid choice')
print('you means zero run on this ball')
print(f'total runs of your:{run} and total wicket of your:{w}')
return run
def comp1(t,b):
r1 = 0
w1 = 0
for loop in range(1,b+1,1):
q = int(input('enter your choice:'))
e = random.randint(1,10)
print('computer choice:',e)
if e == q:
w1 += 1
print('no.of wicket of computer:',w1)
if w1 == t:
break
else:
r1 += e
print('total run of computer:',r1)
global p
if p < r1:
break
print(f'total runs for computer:{r1} and total wicket for computer:{w1}')
return r1
def coin():
return random.choice(['Head','Tail'])
print('\t\t\tMenu\t\t\t\n')
print('''Menu1: 1-6 runs
Menu2: 1-10 runs\n''')
menu = int(input('Enter your menu number from (1-2):'))
wi = int(input('enter the no.of wicket:'))
bal = int(input('enter th no.of ball:'))
t = input('Enter your choice Head or Tail:')
r = coin()
print(f'The result of toss is {r}\n')
def s(o,k):
if o < k:
print('computer won')
elif o == k:
print('tied')
elif o > k:
print('you won')
def u(p,r):
if p < r:
print('computer won')
elif p == r:
print('tied')
elif p > r:
print('you won')
if t == r.lower():
print('You won the toss')
y = input('Enter batting or bolwing:')
if menu == 1:
if y.lower() == 'bat' or y.lower() == 'batting':
o = you_firstbatting(t=wi,b=bal)
print('\nyour turn to bolwing\n')
k = comp(t=wi,b=bal)
s(o=o,k=k)
else:
k = comp_firstbatting(t=wi,b=bal)
print('\nyour turn to batting\n')
o = you(t=wi,b=bal)
s(o=o,k=k)
elif menu == 2:
if y.lower() == 'bat' or y.lower() == 'batting':
p = you_firstbatting1(t=wi,b=bal)
print('\nyour turn to bolwing\n')
r = comp1(t=wi,b=bal)
u(r=r,p=p)
else:
r = comp_firstbatting1(t=wi,b=bal)
print('\nyour turn to batting\n')
p = you1(t=wi,b=bal)
u(r=r,p=p)
else:
print('''Invalid menu number.
Please restart game ''')
elif t == r[0].lower():
print('You won the toss')
y = input('Enter batting or bolwing:')
if menu == 1:
if y.lower == 'bat' or y.lower() == 'bat':
o = you_firstbatting(t=wi,b=bal)
print('\nyour turn to bolwing\n')
k = comp(t=wi,b=bal)
s(o=o,k=k)
else:
k = comp_firstbatting(t=wi,b=bal)
print('\nyour turn to batting\n')
o = you(t=wi,b=bal)
s(o=o,k=k)
elif menu == 2:
if y.lower() == 'bat' or y.lower() == 'batting':
p = you_firstbatting1(t=wi,b=bal)
print('\nyour turn to bolwing\n')
r = comp1(t=wi,b=bal)
u(r=r,p=p)
else:
r = comp_firstbatting1(t=wi,b=bal)
print('\nyour turn to batting\n')
p = you1(t=wi,b=bal)
u(r=r,p=p)
else:
print('''Invalid menu number.
Please restart game ''')
else:
if menu == 1:
print('Computer won the toss')
print('Computer chosen to bat')
if menu == 1:
k = comp_firstbatting(t=wi,b=bal)
print('\nyour turn to batting\n')
o = you(t=wi,b=bal)
s(o=o,k=k)
elif menu == 2:
r = comp_firstbatting1(t=wi,b=bal)
print('\nyour turn to batting\n')
p = you1(t=wi,b=bal)
u(r=r,p=p)