Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- teamA=("Team A")
- teamB=("Team B")
- teamPlayerList=[]
- def main():
- totalAScore=0
- print (" +-++-++-++-++-++-++-+ +-++-++-++-++-++-+ +-++-++-+")
- print (" |C||R||I||C||K||E||T| |S||C||O||R||E||R| |2|.|0| |")
- print (" +-++-++-++-++-++-++-+ +-++-++-++-++-++-+ +-++-++-+")
- #Input variables
- teamOvers = int(input("\nPlease enter the number of overs (6 Balls) each Team will bat: "))
- #Placing input into another variable for calculations in runLoop
- totalABalls=teamOvers*6
- totalBBalls=teamOvers*6
- #Calling first function with 3 arguments
- wicketsA,totalABalls,teamAOvers,totalAScore=runLoop(totalABalls,teamOvers,teamA,totalAScore)
- wicketsB,totalBBalls,teamBOvers,totalBScore=runLoop(totalBBalls,teamOvers,teamB,totalAScore)
- finalTally(totalAScore,totalBScore,teamAOvers,teamBOvers,totalABalls,totalBBalls,wicketsA,wicketsB)
- def runLoop(totalBalls,teamOvers,team,totalAScore):
- """
- Local variables
- """
- totalScore=0
- overs=(totalBalls/6)
- totalBallsOne=totalBalls
- wickets=10
- print('\n***********************')
- print('**** %s to Bat ''****' % team)
- print('***********************')
- setCricketers()
- """
- Run, wicket and calculation logic for both Teams
- """
- while(totalBalls > 0):
- totalBalls = totalBalls - 1
- print('\nTotal balls left for',(team),':',(totalBalls+1))
- runs=getRuns(totalScore,wickets,teamPlayerList)
- totalScore = runs
- if(team=="Team B" and totalScore>totalAScore):
- print('Team B has out-run Team A')
- break
- print('\nTotal running score for',(team),'(runs/wickets):',totalScore,"/",wickets)
- if (wickets <= 0 or totalBalls == 0):
- print ("All out...")
- print ("\n Final Score ")
- print ("+------------------------+")
- print ('\n1. Final Score for',(team),': %d' % totalScore)
- print ("2. Wickets lost: %d" % (10-wickets))
- print ("3. Number of overs played: %.1f" % ((totalBalls*overs) / totalBallsOne))
- break
- return wickets,totalBalls,overs,totalScore
- def addCricketers(wickets):
- if(wickets==9):
- player3=input(str('Please enter the new batsman at the striker end: '))
- teamPlayerList.insert(2,player3)
- elif(wickets==8):
- player4=input(str('Please enter the new batsman at the striker end: '))
- teamPlayerList.insert(3,player4)
- elif(wickets==7):
- player5=input(str('Please enter the new batsman at the striker end: '))
- teamPlayerList.insert(4,player5)
- elif(wickets==6):
- player6=input(str('Please enter the new batsman at the striker end: '))
- teamPlayerList.insert(5,player6)
- elif(wickets==5):
- player7=input(str('Please enter the new batsman at the striker end: '))
- teamPlayerList.insert(6,player7)
- elif(wickets==4):
- player8=input(str('Please enter the new batsman at the striker end: '))
- teamPlayerList.insert(7,player8)
- else:
- player9=input(str('Please enter the new batsman at the striker end: '))
- teamPlayerList.insert(8,player9)
- return teamPlayerList
- def setCricketers():
- print('Please enter first two cricketers batting for Team A')
- player1=input(str('Please enter the batsman at the striker end: '))
- player2=input(str('Please enter the batsman at the non-striker end: '))
- teamPlayerList.insert(0,player1)
- teamPlayerList.insert(1,player2)
- return teamPlayerList
- def getRuns(totalScore,wickets,teamPlayerList):
- while(1):
- try:
- if(totalScore%2==0):
- runs=int(input("\nEnter runs for the striker %s, or -1 for a wicket " % teamPlayerList[0]))
- else:
- runs=int(input("\nEnter runs for the striker %s, or -1 for a wicket " % teamPlayerList [1]))
- if(runs<0):
- wickets=(wickets-1)
- elif(runs<7):
- return runs,wickets
- else:
- print("Invalid run(s) entered. Please try again.")
- except Exception as err:
- print(err)
- print("Please try again.")
- def finalTally(totalAScore,totalBScore,teamAOvers,teamBOvers,totalABalls,totalBBalls,wicketsA,wicketsB):
- teamA_Win=totalAScore-totalBScore
- teamB_Win=totalBScore-totalAScore
- totalWickets=wicketsB-wicketsA
- """
- Scoreboard display, and winner logic.
- """
- print ("\n\n\n\n\n+-++-++-++-++-++-++-+ +-+-++-++-+")
- print ("|S||C||O||R||E|| |B||O||A||R||D||")
- print ("+-++-++-++-++-++-++-+-+-+-+-+-+-+")
- print ("\nTeam A")
- print ("+--------------+")
- print ("Score: %d" % totalAScore)
- print (("Overs Played: %d") % (teamAOvers))
- print ("Wickets lost: %d" % (10-wicketsA))
- print ("\nTeam B ")
- print ("+--------------+")
- print ("Score: %d" % totalBScore)
- print ("Overs Played: %d" % (teamBOvers))
- print ("Wickets lost: %d" % (10-wicketsB))
- if (totalAScore>totalBScore):
- print ("\nTEAM A THE WINNER!!! BY %d RUNS!" % teamA_Win)
- if (wicketsB > wicketsA):
- print ("\nTeam B won the match by %d wickets!" % totalWickets)
- if (totalBScore > totalAScore):
- print ("\nTEAM B THE WINNER!!! BY %d RUNS!" % teamB_Win)
- if (totalAScore == totalBScore):
- print ("\nWE HAVE A DRAW!!! REMATCH")
- main()
Advertisement
Add Comment
Please, Sign In to add comment