Advertisement
richbpark

topScorers-02

Feb 1st, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. import random
  2.  
  3. def makeScoreList(numItems): # Make a random list of numbers each having a
  4. scores = [] # value between 0 and 10
  5. for x in range (numItems):
  6. scores.append(random.randint(0, 10))
  7. return scores
  8.  
  9. def count (scoreVal, scoreList): # For a particular value calculate and return
  10. numScore = 0 # the number of occurances of that value.
  11. for item in scoreList:
  12. if item == scoreVal:
  13. numScore += 1
  14. return numScore
  15.  
  16. def scoreStats(scoreValues): # Put the number of value occurances in a list and return the list.
  17. makeStatList=[]
  18. for i in range (11):
  19. makeStatList.append(count(i, scoreValues))
  20. print()
  21. return makeStatList
  22.  
  23. def statList(): # Descriptive list of the quantity of each value.
  24. for item in range(len(scoreStatList)):
  25. print ("Number of ",item,"'s"," = ",(scoreStatList[item]),sep="")
  26.  
  27.  
  28. ###################-MAIN PYTHON PROGRAM LOOP- ##########################
  29.  
  30. # List variable containing the output from the makeScoreList function.
  31. scoreValueList = makeScoreList(30)
  32. # List variable containing the quantity of each grade value.
  33. scoreStatList = scoreStats(scoreValueList)
  34.  
  35.  
  36. print("A random, unordered list of values (0-10) representing student scores.\n", scoreValueList)
  37. print()
  38. print("The number of times each value occurs.\n", scoreStatList)
  39. print()
  40. print("A descriptive breakout of the value quantities.\n")
  41. statList()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement