Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plot
- import random
- def count(mark,alist):
- counts = 0 # Initialise a variable for counting scores of ten
- for countr in alist:
- if countr == mark:
- counts += 1
- return counts
- def ucount(mark,alist):
- counts = 0 # Initialise a variable for counting scores of ten
- for countr in alist:
- if countr < mark:
- counts += 1
- return counts
- def numberAtEachCore(alist):
- #create an zeroed results 'array'
- res=[]
- for i in range(11):
- res.append(0)
- for cScore in alist:
- res[cScore]+=1
- return res
- def print_data(alist):
- print('\nStudent Performance')
- for i in range(len(alist)):
- print('{0} students) scored {1}'.format(alist[i],i))
- #set up some sample scores
- scores = []
- for x in range (0, 50):
- scores.append(random.randint(0, 10))
- print('Generated \'random\' scores: {0}'.format(scores))
- top_scorers = count(10, scores)
- lowmark=4
- low_scorers = ucount(lowmark, scores)
- print("{0} learners got top marks".format(top_scorers))
- print("{0} learners got under {1} marks".format(low_scorers,lowmark))
- performance=numberAtEachCore(scores)
- print(performance)
- print_data(performance)
- #plot results with red bars for fails 3 or less,
- #orange 4, yellow satisfactory 5-8,
- #green excellent 9 or 100
- plot.bar(range(11), performance, align='center',alpha=0.99, color=['red', 'red', 'red', 'red', 'orange', 'yellow', 'yellow', 'yellow', 'yellow', 'green', 'green'])
- plot.xticks(range(11))
- plot.ylabel('Score frequency')
- plot.xlabel('Score')
- plot.title('Scores on a quiz\nred: poor,orange:OK,yellow:satisfactory,green:excellent')
- plot.show()
- plot.savefig(fname="Quiz Chart.png")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement