Advertisement
xavicano

Untitled

Aug 18th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. from random import randint
  2. import matplotlib.pyplot as plot
  3.  
  4. def count(target,scores):
  5.     counter = 0    # Initialise a variable for counting scores of ten
  6.  
  7.     for score in scores:
  8.       if score == target:
  9.           counter += 1
  10.      
  11.     #print("{0} learners got top marks".format(counter))
  12.     return counter
  13.    
  14. def count_frequency( to_num, scores_freq):
  15.     for i in range(to_num+1):
  16.         scores_freq.append(count(i,scores))
  17.  
  18.  
  19. scores = []
  20. scores_freq=[]
  21.  
  22.  
  23. for x in range (0, 30):
  24.   scores.append(randint(0, 10))    # Generate a random number from 0 to 10 and append to scores
  25.  
  26. print(scores)
  27. print(" Num of 10",count(10,scores))   # Count how many scores 10
  28.  
  29. count_frequency(10, scores_freq)
  30.  
  31.  
  32. plot.bar(range(11), scores_freq, align='center', alpha=1)
  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="Quiz Chart.png")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement