#4q: Codding in Python {1-Player : HAND CRICKET}
import random as r
hits=[1,1,2,3,3,3,4,4,4,5,5,5,6,6,6,6]
toss=['HEADS','TAILS']
toss1=str(input('Enter HEADS or TAILS: '))
toss2=r.choice(toss)
if toss1==toss2:
print('You won the toss!')
bb=input('BAT or BALL first: ')
if bb=='BAT':
print()
print()
print('You are batting first.')
wickets=int(input('Enter number of Wickets: '))
wic=0
runs=[]
while wickets>wic:
run=sum(runs)
qwert=[run,'/',wic]
for tttt in (qwert):
print(tttt,end="")
print()
for rr in range(100):
rh=int(input('What to hit (1,2,3,4,5,6): '))
if rh in (hits):
bh=r.choice(hits)
print('You hit: ',rh)
print('Computer hits: ',bh)
if rh==bh:
print('Out!')
wic+=1
else:
runs.append(rh)
break
else:
print('Wrong input!.')
if wickets==wic:
print()
print()
print('You are bowling now.')
print('Computer has to score ',run+1, ' in ',wickets,' wickets')
print()
runs=[]
wickets1=wickets
wic1=0
runs1=[]
while wickets1>wic1:
run1=sum(runs1)
qwert1=[run1,'/',wic1]
for tttt in (qwert1):
print(tttt,end="")
print()
rh1=r.choice(hits)
if run<run1:
print('Computer wins! by ',(wickets1-wic1),' wickets.')
break
else:
(print('Runs required are: ',(run-run1)+1))
for we in range(100):
bh1=int(input('What to hit (1,2,3,4,5,6): '))
if bh1 in (hits):
print('Computer hits ',rh1)
print('You hit ',bh1)
if rh1==bh1:
print('Out!')
wic1+=1
else:
runs1.append(rh1)
break
else:
print("Wrong input!")
if wickets1<=wic1:
print("You won! by ",(run-run1+1),' runs.')
break
if bb=='BALL':
print()
print()
print('You are bowling first.')
wickets=int(input('Enter number of Wickets: '))
wickets1=wickets
wic1=0
runs1=[]
while wickets1>wic1:
run1=sum(runs1)
qwert1=[run1,'/',wic1]
for tttt in (qwert1):
print(tttt,end="")
print()
if wickets1<=wic1:
break
else:
rh1=r.choice(hits)
for we in range(100):
bh1=int(input('What to hit (1,2,3,4,5,6): '))
if bh1 in (hits):
print('Computer hits ',rh1)
print('You hit ',bh1)
if rh1==bh1:
print('Out!')
wic1+=1
break
else:
runs1.append(rh1)
break
else:
print("Wrong input!")
if wickets1<=wic1:
print()
print()
print('You are batting now;')
print('You have to score ',run1+1, ' in ',wickets,' wickets')
wic=0
runs=[]
while wickets>wic:
run=sum(runs)
qwert=[run,'/',wic]
for tttt in (qwert):
print(tttt,end="")
print()
if run1<run:
print('You won by ',(wickets-wic))
break
else:
print('Runs required are ',(run1-run)+1)
rh=int(input('What to hit (1,2,3,4,5,6): '))
for we in range(100):
bh=r.choice(hits)
if bh1 in (hits):
print('Computer hits ',bh)
print('You hit ',rh)
if rh==bh:
print('Out!')
wic+=1
else:
runs.append(rh)
break
else:
print("Wrong input!")
if wickets<=wic:
print('Computer wins by ',(run1-run+1))
break
else:
print('You lost the toss!')
tpc=['BAT','BALL']
bb=r.choice(tpc)
if bb=='BAT':
print()
print()
print('You are batting first.')
wickets=int(input('Enter number of Wickets: '))
wic=0
runs=[]
while wickets>wic:
run=sum(runs)
qwert=[run,'/',wic]
for tttt in (qwert):
print(tttt,end="")
print()
for rr in range(100):
rh=int(input('What to hit (1,2,3,4,5,6): '))
if rh in (hits):
bh=r.choice(hits)
print('You hit: ',rh)
print('Computer hits: ',bh)
if rh==bh:
print('Out!')
wic+=1
else:
runs.append(rh)
break
else:
print('Wrong input!.')
if wickets==wic:
print()
print()
print('You are bowling now.')
print('Computer has to score ',run+1, ' in ',wickets,' wickets')
print()
runs=[]
wickets1=wickets
wic1=0
runs1=[]
while wickets1>wic1:
run1=sum(runs1)
qwert1=[run1,'/',wic1]
for tttt in (qwert1):
print(tttt,end="")
print()
rh1=r.choice(hits)
if run<run1:
print('Computer wins! by ',(wickets1-wic1),' wickets.')
break
else:
(print('Runs required are: ',(run-run1+1)))
for we in range(100):
bh1=int(input('What to hit (1,2,3,4,5,6): '))
if bh1 in (hits):
print('Computer hits ',rh1)
print('You hit ',bh1)
if rh1==bh1:
print('Out!')
wic1+=1
else:
runs1.append(rh1)
break
else:
print("Wrong input!")
if wickets1<=wic1:
print("You won! by ",(run-run1+1),' runs.')
break
if bb=='BALL':
print()
print()
print('You are bowling first.')
wickets=int(input('Enter number of Wickets: '))
wickets1=wickets
wic1=0
runs1=[]
while wickets1>wic1:
run1=sum(runs1)
qwert1=[run1,'/',wic1]
for tttt in (qwert1):
print(tttt,end="")
print()
if wickets1<=wic1:
break
else:
rh1=r.choice(hits)
for we in range(100):
bh1=int(input('What to hit (1,2,3,4,5,6): '))
if bh1 in (hits):
print('Computer hits ',rh1)
print('You hit ',bh1)
if rh1==bh1:
print('Out!')
wic1+=1
break
else:
runs1.append(rh1)
break
else:
print("Wrong input!")
if wickets1<=wic1:
print()
print()
print('You are bating now.')
print('You have to score ',run1+1, ' in ',wickets,' wickets')
wic=0
runs=[]
while wickets>wic:
run=sum(runs)
qwert=[run,'/',wic]
for tttt in (qwert):
print(tttt,end="")
print()
if run1<run:
print('You won by ',(wickets-wic),' wickets')
break
else:
print('Runs required are ',(run1-run)+1)
rh=int(input('What to hit (1,2,3,4,5,6): '))
for we in range(100):
bh=r.choice(hits)
if bh1 in (hits):
print('Computer hits ',bh)
print('You hit ',rh)
if rh==bh:
print('Out!')
wic+=1
break
else:
runs.append(rh)
break
else:
print("Wrong input!")
if wickets<=wic:
print('Computer wins by ',(run1-run))
break
hits=[1,1,2,3,3,3,4,4,4,5,5,5,6,6,6,6]
toss=['HEADS','TAILS']
toss1=str(input('Enter HEADS or TAILS: '))
toss2=r.choice(toss)
if toss1==toss2:
print('You won the toss!')
bb=input('BAT or BALL first: ')
if bb=='BAT':
print()
print()
print('You are batting first.')
wickets=int(input('Enter number of Wickets: '))
wic=0
runs=[]
while wickets>wic:
run=sum(runs)
qwert=[run,'/',wic]
for tttt in (qwert):
print(tttt,end="")
print()
for rr in range(100):
rh=int(input('What to hit (1,2,3,4,5,6): '))
if rh in (hits):
bh=r.choice(hits)
print('You hit: ',rh)
print('Computer hits: ',bh)
if rh==bh:
print('Out!')
wic+=1
else:
runs.append(rh)
break
else:
print('Wrong input!.')
if wickets==wic:
print()
print()
print('You are bowling now.')
print('Computer has to score ',run+1, ' in ',wickets,' wickets')
print()
runs=[]
wickets1=wickets
wic1=0
runs1=[]
while wickets1>wic1:
run1=sum(runs1)
qwert1=[run1,'/',wic1]
for tttt in (qwert1):
print(tttt,end="")
print()
rh1=r.choice(hits)
if run<run1:
print('Computer wins! by ',(wickets1-wic1),' wickets.')
break
else:
(print('Runs required are: ',(run-run1)+1))
for we in range(100):
bh1=int(input('What to hit (1,2,3,4,5,6): '))
if bh1 in (hits):
print('Computer hits ',rh1)
print('You hit ',bh1)
if rh1==bh1:
print('Out!')
wic1+=1
else:
runs1.append(rh1)
break
else:
print("Wrong input!")
if wickets1<=wic1:
print("You won! by ",(run-run1+1),' runs.')
break
if bb=='BALL':
print()
print()
print('You are bowling first.')
wickets=int(input('Enter number of Wickets: '))
wickets1=wickets
wic1=0
runs1=[]
while wickets1>wic1:
run1=sum(runs1)
qwert1=[run1,'/',wic1]
for tttt in (qwert1):
print(tttt,end="")
print()
if wickets1<=wic1:
break
else:
rh1=r.choice(hits)
for we in range(100):
bh1=int(input('What to hit (1,2,3,4,5,6): '))
if bh1 in (hits):
print('Computer hits ',rh1)
print('You hit ',bh1)
if rh1==bh1:
print('Out!')
wic1+=1
break
else:
runs1.append(rh1)
break
else:
print("Wrong input!")
if wickets1<=wic1:
print()
print()
print('You are batting now;')
print('You have to score ',run1+1, ' in ',wickets,' wickets')
wic=0
runs=[]
while wickets>wic:
run=sum(runs)
qwert=[run,'/',wic]
for tttt in (qwert):
print(tttt,end="")
print()
if run1<run:
print('You won by ',(wickets-wic))
break
else:
print('Runs required are ',(run1-run)+1)
rh=int(input('What to hit (1,2,3,4,5,6): '))
for we in range(100):
bh=r.choice(hits)
if bh1 in (hits):
print('Computer hits ',bh)
print('You hit ',rh)
if rh==bh:
print('Out!')
wic+=1
else:
runs.append(rh)
break
else:
print("Wrong input!")
if wickets<=wic:
print('Computer wins by ',(run1-run+1))
break
else:
print('You lost the toss!')
tpc=['BAT','BALL']
bb=r.choice(tpc)
if bb=='BAT':
print()
print()
print('You are batting first.')
wickets=int(input('Enter number of Wickets: '))
wic=0
runs=[]
while wickets>wic:
run=sum(runs)
qwert=[run,'/',wic]
for tttt in (qwert):
print(tttt,end="")
print()
for rr in range(100):
rh=int(input('What to hit (1,2,3,4,5,6): '))
if rh in (hits):
bh=r.choice(hits)
print('You hit: ',rh)
print('Computer hits: ',bh)
if rh==bh:
print('Out!')
wic+=1
else:
runs.append(rh)
break
else:
print('Wrong input!.')
if wickets==wic:
print()
print()
print('You are bowling now.')
print('Computer has to score ',run+1, ' in ',wickets,' wickets')
print()
runs=[]
wickets1=wickets
wic1=0
runs1=[]
while wickets1>wic1:
run1=sum(runs1)
qwert1=[run1,'/',wic1]
for tttt in (qwert1):
print(tttt,end="")
print()
rh1=r.choice(hits)
if run<run1:
print('Computer wins! by ',(wickets1-wic1),' wickets.')
break
else:
(print('Runs required are: ',(run-run1+1)))
for we in range(100):
bh1=int(input('What to hit (1,2,3,4,5,6): '))
if bh1 in (hits):
print('Computer hits ',rh1)
print('You hit ',bh1)
if rh1==bh1:
print('Out!')
wic1+=1
else:
runs1.append(rh1)
break
else:
print("Wrong input!")
if wickets1<=wic1:
print("You won! by ",(run-run1+1),' runs.')
break
if bb=='BALL':
print()
print()
print('You are bowling first.')
wickets=int(input('Enter number of Wickets: '))
wickets1=wickets
wic1=0
runs1=[]
while wickets1>wic1:
run1=sum(runs1)
qwert1=[run1,'/',wic1]
for tttt in (qwert1):
print(tttt,end="")
print()
if wickets1<=wic1:
break
else:
rh1=r.choice(hits)
for we in range(100):
bh1=int(input('What to hit (1,2,3,4,5,6): '))
if bh1 in (hits):
print('Computer hits ',rh1)
print('You hit ',bh1)
if rh1==bh1:
print('Out!')
wic1+=1
break
else:
runs1.append(rh1)
break
else:
print("Wrong input!")
if wickets1<=wic1:
print()
print()
print('You are bating now.')
print('You have to score ',run1+1, ' in ',wickets,' wickets')
wic=0
runs=[]
while wickets>wic:
run=sum(runs)
qwert=[run,'/',wic]
for tttt in (qwert):
print(tttt,end="")
print()
if run1<run:
print('You won by ',(wickets-wic),' wickets')
break
else:
print('Runs required are ',(run1-run)+1)
rh=int(input('What to hit (1,2,3,4,5,6): '))
for we in range(100):
bh=r.choice(hits)
if bh1 in (hits):
print('Computer hits ',bh)
print('You hit ',rh)
if rh==bh:
print('Out!')
wic+=1
break
else:
runs.append(rh)
break
else:
print("Wrong input!")
if wickets<=wic:
print('Computer wins by ',(run1-run))
break
Download CODES here.
Comments