Scenario: A teacher has recorded the scores of 10 students on a recent computer science quiz. The scores are stored in a 1D array. The quiz was out of 50 points. Build a small program to perform a basic analysis of the results.
Data
quiz_scores = [45, 32, 28, 50, 15, 41, 39, 22, 48, 35]
Your tasks
Analyse these scores by iterating through the array — not by using sum(), max() or min().
- Calculate the average score — total all scores, then divide by the number of students. Print the average.
- Identify the highest and lowest scores — print both values.
- Count passing students — a pass is 25 or more points. Print how many students passed.
💡 Try the whole challenge in your editor first. Only reveal the solution when you have had a proper go.
Solution
quiz_scores = [45, 32, 28, 50, 15, 41, 39, 22, 48, 35]
total = 0
highest = quiz_scores[0]
lowest = quiz_scores[0]
passes = 0
for score in quiz_scores:
total = total + score
if score > highest:
highest = score
if score < lowest:
lowest = score
if score >= 25:
passes = passes + 1
average = total / len(quiz_scores)
print("Average quiz score:", average)
print("Highest score:", highest)
print("Lowest score:", lowest)
print("Number of passing students:", passes)
Example output:
Average quiz score: 35.5
Highest score: 50
Lowest score: 15
Number of passing students: 8