Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #count frequency distribution in a range of scores
- import random
- import matplotlib.pyplot as plot
- # count number of specified items in a list
- def count(value, data):
- total = 0
- for item in data:
- if item==value:
- total += 1
- return total
- scores = []
- score_frequency = []
- # seed the scores list
- for x in range (0, 30):
- scores.append(random.randint(0, 10))
- # now count frequency of each score and append to frequency list
- for x in range (0, 11):
- score_frequency.append(count(x,scores))
- # plot bar chart
- plot.bar(range(11), score_frequency, align='center', alpha=0.5)
- plot.xticks(range(11))
- plot.ylabel('Score frequency')
- plot.title('Scores on a quiz')
- plot.savefig('Quiz_Chart.png')
- plot.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement