Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- def makeScoreList(numItems): # Make a random list of numbers each having a
- scores = [] # value between 0 and 10
- for x in range (numItems):
- scores.append(random.randint(0, 10))
- return scores
- def count (scoreVal, scoreList): # For a particular value calculate and return
- numScore = 0 # the number of occurances of that value.
- for item in scoreList:
- if item == scoreVal:
- numScore += 1
- return numScore
- def scoreStats(scoreValues): # Put the number of value occurances in a list and return the list.
- makeStatList=[]
- for i in range (11):
- makeStatList.append(count(i, scoreValues))
- print()
- return makeStatList
- def statList(): # Descriptive list of the quantity of each value.
- for item in range(len(scoreStatList)):
- print ("Number of ",item,"'s"," = ",(scoreStatList[item]),sep="")
- ###################-MAIN PYTHON PROGRAM LOOP- ##########################
- # List variable containing the output from the makeScoreList function.
- scoreValueList = makeScoreList(30)
- # List variable containing the quantity of each grade value.
- scoreStatList = scoreStats(scoreValueList)
- print("A random, unordered list of values (0-10) representing student scores.\n", scoreValueList)
- print()
- print("The number of times each value occurs.\n", scoreStatList)
- print()
- print("A descriptive breakout of the value quantities.\n")
- statList()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement