Advertisement
farrismp

Plotting results

May 1st, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. from random import randint
  2. import matplotlib.pyplot as plot
  3.  
  4. # My function
  5. def count(item, scores):
  6. count = 0
  7. for score in scores:
  8. if score == item:
  9. count += 1
  10. return count
  11. # End of my function
  12.  
  13.  
  14. # Generate a 30 random numbers from 0 to 10 and append to scores
  15. scores = []
  16. for x in range (0, 30):
  17. scores.append(randint(0, 10))
  18.  
  19. print(scores)
  20.  
  21. scores_count = []
  22. for score in range(0,11):
  23. scores_count.append(count(score, scores))
  24.  
  25. plot.bar(range(11), scores_count, align='center', alpha=0.5)
  26.  
  27. plot.xticks(range(11))
  28. plot.ylabel('Score frequency')
  29. plot.title('Scores on a quiz')
  30.  
  31. plot.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement