Advertisement
brendan-stanford

scores_summary

Aug 22nd, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. import matplotlib.pyplot as plot
  2. from random import randint
  3.  
  4. #function checks for given score and increases mark counter for eventual return after completion
  5. def mark_count(score_list, grade):
  6. mark = 0
  7. for score in score_list:
  8. if score == grade:
  9. mark += 1
  10. return mark
  11.  
  12. #list stores randomly generated scores and frequency of each score between 0-10
  13. scores = []
  14. frequency = []
  15.  
  16. for x in range(0, 30):
  17. scores.append(randint(0,10))
  18.  
  19. #scores are printed for list review
  20. print(scores)
  21.  
  22. #counter identifying score between 0-10 is set and loop executes mark_count to count each score frequency from 0-10; results stored in frequency
  23. count = 0
  24. for i in range(11):
  25. y = mark_count(scores, i)
  26. frequency.append(y)
  27. print("{0} learners got a score of ".format(y) + str(count))
  28. count += 1
  29. print(frequency)
  30.  
  31. #creates a bar graph of frequency list data
  32. plot.bar(range(11), frequency, align='center', alpha=0.5)
  33.  
  34. plot.xticks(range(11))
  35. plot.ylabel('Score Frequency')
  36. plot.title('Scores on a Quiz')
  37.  
  38. plot.show()
  39. plot.savefig(fname="Freq-Chart.png")
  40. print("done!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement