Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Generates a random list of scores from 0 to 10, calcs the frequency of each
- #score then displays this on a bar graph
- import matplotlib.pyplot as plot
- import random
- def count(num,list):
- tally = 0
- for score in list:
- if score == num:
- tally += 1
- return tally
- scores = []
- frequency = []
- for x in range (0, 30):
- scores.append(random.randint(0, 10))
- print(scores)
- for i in range(10):
- eachcount = count(i, scores) # Count function called here
- frequency.append(eachcount)
- i += 1
- print(frequency)
- plot.bar(range(10), frequency, align='center', alpha=0.5)
- plot.xticks(range(10))
- 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