Advertisement
kevinbocky

bar_graph.py

Jan 29th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. import random #import from the random function
  2. import matplotlib.pyplot as plot
  3.  
  4. grades = [] #create empty list called grades
  5. tens = [] #create empty list called tens
  6. lowscore = []
  7. for x in range(0, 30): # loop range 30
  8. grades.append(random.randint(0,10)) #append in grades a random number 0 - 10
  9.  
  10. print(grades)
  11.  
  12.  
  13. for item in grades: #for every item in grades, if equal to 10, put in tens list
  14. if item == 10:
  15. tens.append(item)
  16. elif item <= 3:
  17. lowscore.append(item) #for every itme in grades if lower then 3 put in lowscore list
  18.  
  19. print(tens)
  20. top_scorers = len(tens) #top_scorers is equal to the length of tens list(int)
  21. low_scorers = len(lowscore) #low_scorers is equal to the length of lowscore list
  22. print(" {} student/s have scored the perfect score".format(top_scorers))
  23. print(" {} student/s have scored lower then 3".format(low_scorers))
  24.  
  25.  
  26.  
  27.  
  28. def chart(performance):
  29. plot.bar(range(11), performance, align='center', alpha=0.5)
  30. plot.xticks(range(11))
  31. plot.ylabel('Score frequency')
  32. plot.title('Scores on a quiz')
  33. plot.show()
  34. plot.savefig(fname="Quiz Chart.png")
  35.  
  36. chart(grades)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement