Advertisement
johnpentyrch

ass2.10

May 1st, 2020
764
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.74 KB | None | 0 0
  1. import matplotlib.pyplot as plot
  2. import random
  3.  
  4.  
  5. def count(mark,alist):
  6.     counts = 0    # Initialise a variable for counting scores of ten
  7.     for countr in alist:
  8.       if countr == mark:
  9.         counts += 1
  10.     return counts
  11.  
  12. def ucount(mark,alist):
  13.     counts = 0    # Initialise a variable for counting scores of ten
  14.     for countr in alist:
  15.       if countr < mark:
  16.         counts += 1
  17.     return counts
  18.  
  19. def numberAtEachCore(alist):
  20.     #create an zeroed results 'array'
  21.     res=[]
  22.     for i in range(11):
  23.         res.append(0)
  24.     for cScore in alist:
  25.         res[cScore]+=1
  26.     return res
  27.    
  28. def print_data(alist):
  29.     print('\nStudent Performance')
  30.     for i in range(len(alist)):
  31.         print('{0} students) scored {1}'.format(alist[i],i))
  32.        
  33.  
  34.  
  35.  
  36. #set up some sample scores
  37. scores = []
  38.  
  39. for x in range (0, 50):
  40.   scores.append(random.randint(0, 10))
  41.  
  42. print('Generated \'random\' scores: {0}'.format(scores))
  43.  
  44. top_scorers = count(10, scores)
  45. lowmark=4
  46. low_scorers = ucount(lowmark, scores)
  47. print("{0} learners got top marks".format(top_scorers))
  48. print("{0} learners got under {1} marks".format(low_scorers,lowmark))
  49.  
  50.  
  51.  
  52. performance=numberAtEachCore(scores)
  53. print(performance)
  54. print_data(performance)
  55.  
  56. #plot results with red bars for fails 3 or less,
  57. #orange 4, yellow satisfactory 5-8,
  58. #green excellent 9 or 100
  59.  
  60. plot.bar(range(11),  performance, align='center',alpha=0.99, color=['red', 'red', 'red', 'red', 'orange', 'yellow', 'yellow', 'yellow', 'yellow', 'green', 'green'])
  61.  
  62. plot.xticks(range(11))
  63. plot.ylabel('Score frequency')
  64. plot.xlabel('Score')
  65. plot.title('Scores on a quiz\nred: poor,orange:OK,yellow:satisfactory,green:excellent')
  66.  
  67. plot.show()
  68. plot.savefig(fname="Quiz Chart.png")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement