#4y: Codding in Python {Hand-Cricket Again}
- aukaat = [1,2,3,4,5,6,6,6,6,5,4,5,4,4,5]
- import random as randi
- def arranger(string):
- k = []
- for i in (string):
- i = i.lower()
- k.append(i)
- l = ''
- for i in (k):
- l = l + i
- return l
- def bat():
- global BATscore, Wickets, balls
- batsman = int(input('Enter Hit number: '))
- bowler = randi.choice(aukaat)
- print('Your choice = ', batsman," Computer's choice = ", bowler)
- print()
- if batsman in range(1,7):
- balls +=1
- if bowler == batsman:
- #out
- print('Out!')
- Wickets += 1
- else:
- BATscore += batsman
- if final == 'ball':
- print()
- print(' Target = ', Target, ' Runs Required = ', Target - BATscore)
- print(' ',BATscore,'/', Wickets, ' (',balls,')')
- def ball():
- global BATscore, Wickets, balls, Target
- bowler = int(input('Enter Hit number: '))
- batsman = randi.choice(aukaat)
- print('Your choice = ', bowler," Computer's choice = ", batsman)
- print()
- if bowler in range(1,7):
- balls +=1
- if bowler == batsman:
- print('Out!')
- Wickets += 1
- else:
- BATscore += batsman
- if final == 'bat':
- print(' Target = ', Target, ' Runs Required = ', Target - BATscore)
- print(' ',BATscore,'/', Wickets, ' (',balls,')')
- totalWIC = int(input("Enter wickets: "))
- coinSS =[ 'heads','tails']
- playSS =[ 'bat','ball']
- toss = str(input('Choose heads or tails: '))
- coin = randi.choice(coinSS)
- if arranger(toss) == coin:
- print('You Won the toss!')
- choice = str(input('Choose BAT or Ball: '))
- final = arranger(choice)
- if arranger(toss) != coin:
- print('You Lost the toss!')
- final = randi.choice(playSS)
- if final == 'bat':print('Computer chose to BOWL First, you will BAT first')
- if final == 'ball':print('Computer chose to BAT First, you will BOWL first')
- print()
- if final == 'bat':
- balls = 0
- BATscore = 0
- Wickets = 0
- while 1==1:
- bat()
- if Wickets == totalWIC :
- print('All out! Computer needs to score ', BATscore + 1, ' to win')
- print()
- print()
- print('You are now bowling')
- Target = BATscore + 1
- break
- balls = 0
- BATscore = 0
- Wickets = 0
- while 1==1:
- ball()
- if BATscore > Target-1:
- print("You lost!")
- break
- if Wickets == totalWIC :
- print('You WON!')
- break
- if final == 'ball':
- balls = 0
- BATscore = 0
- Wickets = 0
- while 1==1:
- Target = BATscore
- ball()
- if Wickets == totalWIC :
- print('All out! You needs to score ', BATscore + 1, ' to win')
- print()
- print()
- print('You are now bowling')
- Target = BATscore + 1
- break
- balls = 0
- BATscore = 0
- Wickets = 0
- while 1==1:
- bat()
- if BATscore > Target-1:
- print("You WON!")
- break
- if Wickets == totalWIC :
- print('You lost!')
- break
Download the same here.
Comments