Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- import matplotlib.pyplot as plot
- # generate random marks out of 10 to represent the results of the quiz taken by a class
- marks=[randint(0,10) for x in range(30) ]
- # quiz scored out of 10
- possible_scores=[x for x in range(11)]
- def count_occurences(occurence,list_of_stuff):
- count=0
- for item in list_of_stuff:
- if item==occurence:
- count+=1
- print("{} appears {} times in the list".format(occurence,count))
- return count
- def count_occurences_ofeach_tolist(possible_scores):
- list_of_scores=[]
- for score in possible_scores:
- count=count_occurences(score,marks)
- list_of_scores.append(count)
- return list_of_scores
- list_of_scores=count_occurences_ofeach_tolist(possible_scores)
- print(list_of_scores)
- plot.barh(range(11), list_of_scores, align='edge', alpha=1.0, color="red",)
- plot.xticks(range(11))
- plot.xlabel('Score frequency')
- plot.ylabel('Marks range')
- plot.title('Scores of class from random generated marks')
- plot.show()
- plot.savefig(filename="Scores_chart_from_random_marks.png")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement