# Program to process Cricket Scores # Worked solution for Wrestling with Python Lab session Jan. 2014 # # Rob Miles # www.wrestlingwithpython.com # # Set the result variables to their initial values # # Set the counters to 0 # total = 0 numberOfDucks = 0 numberOfCenturies = 0 # Put these initial values at their opposite extremes # highestScore = 0 lowestScore = 500 # for i in range(1,12): # go round this loop 11 times - once for each score value score = -1 # force the reading loop to go round at least once while score < 0 or score > 500: # read in a value scoreString = input('Enter a score in the range 0 to 500 : ') score = int(scoreString) # Now we have a score - process it total = total + score if score == 0: numberOfDucks = numberOfDucks + 1 if score > 99: numberOfCenturies = numberOfCenturies + 1 if score > highestScore: highestScore = score if score < lowestScore: lowestScore = score # # Now print the results # print('Cricket Score Summary') print print('Total score is: ',total) print('Average score is: ',total / 11) print('Number of ducks is: ', numberOfDucks) print('Number of centuries is: ',numberOfCenturies) print('Highest score is: ', highestScore) print('Lowest score is: ', lowestScore)