2.2 Counting passes
You have an array that stores the test scores for a group of pupils. Each score is a whole number. Your task is to check each score and decide if it meets or passes the set pass mark. In this case, the pass mark is 14. Go through the list of scores one by one, count how many pupils have a score that is greater than or equal to the pass mark, and then display the total number of passes at the end.
scores = [12, 18, 15, 20, 9, 14]
Number of passes: 4
set scores to [12, 18, 15, 20, 9, 14]
set pass_mark to 14
set count to 0
loop for length of scores array
if score at current position is greater than or equal to pass_mark
set count to count + 1
print "Number of passes:", count
scores = [12, 18, 15, 20, 9, 14]
pass_mark = 14
count = 0
for i in range(len(scores)):
if scores[i] >= pass_mark:
count = count + 1
print("Number of passes:", count)
# List of scores
scores = [12, 18, 15, 20, 9, 14]
# Pass mark to compare against
pass_mark = 14
# Counter starts at 0
count = 0
# Go through each score
for i in range(len(scores)):
# If score meets or beats the pass mark, add 1 to the counter
if scores[i] >= pass_mark:
count = count + 1
# Show the total number of passes
print("Number of passes:", count)
Extension
The program should count how many pupils have passed and how many have failed based on the pass mark.
A pass is when the score is greater than or equal to the pass mark, and a fail is when the score is less than the pass mark.
After counting, the program should also work out the percentage of pupils who passed and the percentage who failed.
Both percentages should be displayed alongside the counts.
Number of passes: 4 (66%) Number of fails: 2 (33%)