Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- import matplotlib.pyplot as plot
- def count(target,scores):
- counter = 0 # Initialise a variable for counting scores of ten
- for score in scores:
- if score == target:
- counter += 1
- #print("{0} learners got top marks".format(counter))
- return counter
- def count_frequency( to_num, scores_freq):
- for i in range(to_num+1):
- scores_freq.append(count(i,scores))
- def max_num(list): # Only for postive numbers
- max=0
- for i in list:
- if i>max:
- max=i
- return max
- def min_num(list):
- min=max_num(list)
- for i in list:
- if i<min:
- min=i
- return min
- def average_num(list):
- average=0
- for i in list:
- average+=i
- return(average/len(list))
- scores = []
- scores_freq=[]
- for x in range (0, 30):
- scores.append(randint(0, 10)) # Generate a random number from 0 to 10 and append to scores
- print(scores)
- print(" Num of 10",count(10,scores)) # Count how many scores 10
- print(" Max = ",max_num(scores)) # Count how many scores 10
- print(" Min = ",min_num(scores)) # Count how many scores 10
- print(" Average = ",average_num(scores)) # Count how many scores 10
- count_frequency(10, scores_freq)
- plot.bar(range(11), scores_freq, align='center', alpha=1)
- plot.xticks(range(11))
- plot.ylabel('Score frequency')
- plot.title('Scores on a quiz')
- plot.show()
- plot.savefig(fname="Quiz Chart.png")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement