Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plot
- from random import randint
- #function checks for given score and increases mark counter for eventual return after completion
- def mark_count(score_list, grade):
- mark = 0
- for score in score_list:
- if score == grade:
- mark += 1
- return mark
- #list stores randomly generated scores and frequency of each score between 0-10
- scores = []
- frequency = []
- for x in range(0, 30):
- scores.append(randint(0,10))
- #scores are printed for list review
- print(scores)
- #counter identifying score between 0-10 is set and loop executes mark_count to count each score frequency from 0-10; results stored in frequency
- count = 0
- for i in range(11):
- y = mark_count(scores, i)
- frequency.append(y)
- print("{0} learners got a score of ".format(y) + str(count))
- count += 1
- print(frequency)
- #creates a bar graph of frequency list data
- plot.bar(range(11), frequency, align='center', alpha=0.5)
- plot.xticks(range(11))
- plot.ylabel('Score Frequency')
- plot.title('Scores on a Quiz')
- plot.show()
- plot.savefig(fname="Freq-Chart.png")
- print("done!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement