Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random #import from the random function
- import matplotlib.pyplot as plot
- grades = [] #create empty list called grades
- tens = [] #create empty list called tens
- lowscore = []
- for x in range(0, 30): # loop range 30
- grades.append(random.randint(0,10)) #append in grades a random number 0 - 10
- print(grades)
- for item in grades: #for every item in grades, if equal to 10, put in tens list
- if item == 10:
- tens.append(item)
- elif item <= 3:
- lowscore.append(item) #for every itme in grades if lower then 3 put in lowscore list
- print(tens)
- top_scorers = len(tens) #top_scorers is equal to the length of tens list(int)
- low_scorers = len(lowscore) #low_scorers is equal to the length of lowscore list
- print(" {} student/s have scored the perfect score".format(top_scorers))
- print(" {} student/s have scored lower then 3".format(low_scorers))
- def chart(performance):
- plot.bar(range(11), performance, align='center', alpha=0.5)
- plot.xticks(range(11))
- plot.ylabel('Score frequency')
- plot.title('Scores on a quiz')
- plot.show()
- plot.savefig(fname="Quiz Chart.png")
- chart(grades)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement