Guest User

sourceexample

a guest
May 16th, 2012
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.53 KB | None | 0 0
  1. teamA=("Team A")
  2. teamB=("Team B")
  3. teamPlayerList=[]
  4.  
  5. def main():
  6.  
  7. totalAScore=0
  8.  
  9. print (" +-++-++-++-++-++-++-+ +-++-++-++-++-++-+ +-++-++-+")
  10. print (" |C||R||I||C||K||E||T| |S||C||O||R||E||R| |2|.|0| |")
  11. print (" +-++-++-++-++-++-++-+ +-++-++-++-++-++-+ +-++-++-+")
  12.  
  13. #Input variables
  14. teamOvers = int(input("\nPlease enter the number of overs (6 Balls) each Team will bat: "))
  15.  
  16. #Placing input into another variable for calculations in runLoop
  17. totalABalls=teamOvers*6
  18. totalBBalls=teamOvers*6
  19.  
  20. #Calling first function with 3 arguments
  21. wicketsA,totalABalls,teamAOvers,totalAScore=runLoop(totalABalls,teamOvers,teamA,totalAScore)
  22.  
  23. wicketsB,totalBBalls,teamBOvers,totalBScore=runLoop(totalBBalls,teamOvers,teamB,totalAScore)
  24.  
  25. finalTally(totalAScore,totalBScore,teamAOvers,teamBOvers,totalABalls,totalBBalls,wicketsA,wicketsB)
  26.  
  27. def runLoop(totalBalls,teamOvers,team,totalAScore):
  28.  
  29. """
  30. Local variables
  31. """
  32. totalScore=0
  33. overs=(totalBalls/6)
  34. totalBallsOne=totalBalls
  35. wickets=10
  36.  
  37. print('\n***********************')
  38. print('**** %s to Bat ''****' % team)
  39. print('***********************')
  40.  
  41. setCricketers()
  42.  
  43. """
  44. Run, wicket and calculation logic for both Teams
  45. """
  46.  
  47.  
  48. while(totalBalls > 0):
  49. totalBalls = totalBalls - 1
  50. print('\nTotal balls left for',(team),':',(totalBalls+1))
  51. runs=getRuns(totalScore,wickets,teamPlayerList)
  52. totalScore = runs
  53. if(team=="Team B" and totalScore>totalAScore):
  54. print('Team B has out-run Team A')
  55. break
  56. print('\nTotal running score for',(team),'(runs/wickets):',totalScore,"/",wickets)
  57. if (wickets <= 0 or totalBalls == 0):
  58. print ("All out...")
  59. print ("\n Final Score ")
  60. print ("+------------------------+")
  61. print ('\n1. Final Score for',(team),': %d' % totalScore)
  62. print ("2. Wickets lost: %d" % (10-wickets))
  63. print ("3. Number of overs played: %.1f" % ((totalBalls*overs) / totalBallsOne))
  64. break
  65. return wickets,totalBalls,overs,totalScore
  66.  
  67. def addCricketers(wickets):
  68.  
  69. if(wickets==9):
  70. player3=input(str('Please enter the new batsman at the striker end: '))
  71. teamPlayerList.insert(2,player3)
  72. elif(wickets==8):
  73. player4=input(str('Please enter the new batsman at the striker end: '))
  74. teamPlayerList.insert(3,player4)
  75. elif(wickets==7):
  76. player5=input(str('Please enter the new batsman at the striker end: '))
  77. teamPlayerList.insert(4,player5)
  78. elif(wickets==6):
  79. player6=input(str('Please enter the new batsman at the striker end: '))
  80. teamPlayerList.insert(5,player6)
  81. elif(wickets==5):
  82. player7=input(str('Please enter the new batsman at the striker end: '))
  83. teamPlayerList.insert(6,player7)
  84. elif(wickets==4):
  85. player8=input(str('Please enter the new batsman at the striker end: '))
  86. teamPlayerList.insert(7,player8)
  87. else:
  88. player9=input(str('Please enter the new batsman at the striker end: '))
  89. teamPlayerList.insert(8,player9)
  90. return teamPlayerList
  91.  
  92. def setCricketers():
  93. print('Please enter first two cricketers batting for Team A')
  94. player1=input(str('Please enter the batsman at the striker end: '))
  95. player2=input(str('Please enter the batsman at the non-striker end: '))
  96. teamPlayerList.insert(0,player1)
  97. teamPlayerList.insert(1,player2)
  98. return teamPlayerList
  99.  
  100.  
  101.  
  102. def getRuns(totalScore,wickets,teamPlayerList):
  103. while(1):
  104. try:
  105. if(totalScore%2==0):
  106. runs=int(input("\nEnter runs for the striker %s, or -1 for a wicket " % teamPlayerList[0]))
  107. else:
  108. runs=int(input("\nEnter runs for the striker %s, or -1 for a wicket " % teamPlayerList [1]))
  109. if(runs<0):
  110. wickets=(wickets-1)
  111. elif(runs<7):
  112. return runs,wickets
  113. else:
  114. print("Invalid run(s) entered. Please try again.")
  115. except Exception as err:
  116. print(err)
  117. print("Please try again.")
  118.  
  119. def finalTally(totalAScore,totalBScore,teamAOvers,teamBOvers,totalABalls,totalBBalls,wicketsA,wicketsB):
  120.  
  121. teamA_Win=totalAScore-totalBScore
  122. teamB_Win=totalBScore-totalAScore
  123. totalWickets=wicketsB-wicketsA
  124.  
  125. """
  126. Scoreboard display, and winner logic.
  127. """
  128. print ("\n\n\n\n\n+-++-++-++-++-++-++-+ +-+-++-++-+")
  129. print ("|S||C||O||R||E|| |B||O||A||R||D||")
  130. print ("+-++-++-++-++-++-++-+-+-+-+-+-+-+")
  131. print ("\nTeam A")
  132. print ("+--------------+")
  133. print ("Score: %d" % totalAScore)
  134. print (("Overs Played: %d") % (teamAOvers))
  135. print ("Wickets lost: %d" % (10-wicketsA))
  136. print ("\nTeam B ")
  137. print ("+--------------+")
  138. print ("Score: %d" % totalBScore)
  139. print ("Overs Played: %d" % (teamBOvers))
  140. print ("Wickets lost: %d" % (10-wicketsB))
  141. if (totalAScore>totalBScore):
  142. print ("\nTEAM A THE WINNER!!! BY %d RUNS!" % teamA_Win)
  143. if (wicketsB > wicketsA):
  144. print ("\nTeam B won the match by %d wickets!" % totalWickets)
  145. if (totalBScore > totalAScore):
  146. print ("\nTEAM B THE WINNER!!! BY %d RUNS!" % teamB_Win)
  147. if (totalAScore == totalBScore):
  148. print ("\nWE HAVE A DRAW!!! REMATCH")
  149.  
  150.  
  151. main()
Advertisement
Add Comment
Please, Sign In to add comment