Advertisement
xavicano

Untitled

Aug 18th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.38 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. def max_num(list):      # Only for postive numbers
  19.     max=0
  20.     for i in list:
  21.         if i>max:
  22.             max=i
  23.     return max
  24.    
  25. def min_num(list):
  26.     min=max_num(list)
  27.     for i in list:
  28.         if i<min:
  29.             min=i
  30.     return min
  31.    
  32. def average_num(list):
  33.     average=0
  34.     for i in list:
  35.         average+=i
  36.     return(average/len(list))
  37.        
  38.    
  39. scores = []
  40. scores_freq=[]
  41.  
  42.  
  43. for x in range (0, 30):
  44.   scores.append(randint(0, 10))    # Generate a random number from 0 to 10 and append to scores
  45.  
  46. print(scores)
  47. print(" Num of 10",count(10,scores))        # Count how many scores 10
  48. print(" Max = ",max_num(scores))            # Count how many scores 10
  49. print(" Min = ",min_num(scores))            # Count how many scores 10
  50. print(" Average = ",average_num(scores))    # Count how many scores 10
  51.  
  52. count_frequency(10, scores_freq)
  53.  
  54.  
  55. plot.bar(range(11), scores_freq, align='center', alpha=1)
  56.  
  57. plot.xticks(range(11))
  58. plot.ylabel('Score frequency')
  59. plot.title('Scores on a quiz')
  60.  
  61. plot.show()
  62. plot.savefig(fname="Quiz Chart.png")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement