Fareehausman00

Untitled

Sep 21st, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #Generates a random list of scores from 0 to 10, calcs the frequency of each
  2. #score then displays this on a bar graph
  3.  
  4. import matplotlib.pyplot as plot
  5. import random
  6.  
  7. def count(num,list):
  8. tally = 0
  9. for score in list:
  10. if score == num:
  11. tally += 1
  12. return tally
  13.  
  14. scores = []
  15. frequency = []
  16. for x in range (0, 30):
  17. scores.append(random.randint(0, 10))
  18. print(scores)
  19.  
  20. for i in range(10):
  21. eachcount = count(i, scores) # Count function called here
  22. frequency.append(eachcount)
  23. i += 1
  24.  
  25. print(frequency)
  26.  
  27. plot.bar(range(10), frequency, align='center', alpha=0.5)
  28.  
  29. plot.xticks(range(10))
  30. plot.ylabel('Score frequency')
  31. plot.title('Scores on a quiz')
  32.  
  33. plot.show()
  34. plot.savefig(fname="Quiz Chart.png")
Advertisement
Add Comment
Please, Sign In to add comment