Advertisement
richbpark

topScorersChart-01

Feb 1st, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. import matplotlib.pyplot as plot
  2. import random
  3.  
  4. def makeScoreList(numItems): # Make a random list of numbers each having a
  5. scores = [] # value between 0 and 10
  6. for x in range (numItems):
  7. scores.append(random.randint(0, 10))
  8. return scores
  9.  
  10. def count (scoreVal, scoreList): # For a particular value calculate and return
  11. numScore = 0 # the number of occurances of that value.
  12. for item in scoreList:
  13. if item == scoreVal:
  14. numScore += 1
  15. return numScore
  16.  
  17. def scoreStats(scoreValues): # Put the number of value occurances in a list and return the list.
  18. makeStatList=[]
  19. for i in range (11):
  20. makeStatList.append(count(i, scoreValues))
  21. print()
  22. return makeStatList
  23.  
  24. def statList(): # Descriptive list of the quantity of each value.
  25. for item in range(len(scoreStatList)):
  26. print ("Number of ",item,"'s"," = ",(scoreStatList[item]),sep="")
  27.  
  28.  
  29. ###################-MAIN PYTHON PROGRAM LOOP- ##########################
  30.  
  31. # List variable containing the output from the makeScoreList function.
  32. scoreValueList = makeScoreList(30)
  33. # List variable containing the quantity of each grade value.
  34. scoreStatList = scoreStats(scoreValueList)
  35.  
  36. # These print line allow checking the output values of the various lists.
  37. #print("A random, unordered list of values (0-10) representing student scores.\n", scoreValueList)
  38. #print()
  39. #print("The number of times each value occurs.\n", scoreStatList)
  40. print()
  41. print("A descriptive breakout of the value quantities.\n")
  42. statList()
  43.  
  44.  
  45. performance = scoreStatList # The list created by the topScorers-02 program.
  46.  
  47. plot.bar(range(11), performance, align='center', alpha=0.5)
  48.  
  49. plot.xticks(range(11))
  50. plot.ylabel('Score frequency')
  51. plot.title('Scores on a quiz')
  52.  
  53. plot.show()
  54. plot.savefig(fname="Quiz Chart.png")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement