• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Prog102 Week 2 Chart challenge

SteveJeff Aug 23rd, 2019 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. from random import randint
2.
3. import matplotlib.pyplot as plot
4. scores = []
5.
6. score10 = []
7.
8. for x in range (0, 30):
9.     scores.append(randint(0, 10)) # generate random number from 0 to 10, add to scores
10.
11. print(scores)
12.
13. tens = 0 # initialise variable for counting scores of ten
14. nines = 0
15. eights = 0
16. sevens = 0
17. sixes = 0
18. fives = 0
19. fours = 0
20. threes = 0
21. twos = 0
22. ones = 0
23. zeros = 0
24.
25. for score in scores:
26.     if score == 10:
27.         tens += 1
28.     if score == 9:
29.         nines += 1
30.     if score == 8:
31.         eights += 1
32.     if score == 7:
33.         sevens += 1
34.     if score == 6:
35.         sixes += 1
36.     if score == 5:
37.         fives += 1
38.     if score == 4:
39.         fours += 1
40.     if score == 3:
41.         threes += 1
42.     if score == 2:
43.         twos += 1
44.     if score == 1:
45.         ones += 1
46.     if score == 0:
47.         zeros += 1
48.
49.
50. score10.append(zeros)
51. score10.append(ones)
52. score10.append(twos)
53. score10.append(threes)
54. score10.append(fours)
55. score10.append(fives)
56. score10.append(sixes)
57. score10.append(sevens)
58. score10.append(eights)
59. score10.append(nines)
60. score10.append(tens)
61.
62.
63. print("\n{0} learners got top marks".format(tens))
64. print()
65. print(score10)
66.
67.
68. plot.bar(range(11), score10, align = "center", alpha= 0.5)
69.
70. plot.xticks(range(11))
71. plot.ylabel("Score frequency")
72. plot.title("Scores on a test")
73.
74. plot.show()
75. plot.savefig(fname = "Chart_chall01.png")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top