Neco 2020 Computer Studies Question 8

Practice essay / theory question 8 from the 2020 Neco Computer Studies examination. This question covers Python programming, File handling, Control structures, Algorithm analysis .

Neco 2020 Computer Studies Essay / Theory
Topics: Python programming File handling Control structures Algorithm analysis
Question 8 NECO • 2020 • COMPUTER_STUDIES • essay

A teacher wants to keep a record of her class’s performance using a simple Python program. The program must read a text file named "scores.txt". Each line of the file contains a student’s name and their score (an integer between 0 and 100) separated by a comma, for example: John Doe,78 Jane Smith,85 ... The program should: 1. Compute the class average. 2. Identify the highest and lowest scores together with the corresponding student names. 3. Assign a grade to each student using the following scale: 70‑100 = A, 60‑69 = B, 50‑59 = C, 40‑49 = D, below 40 = F. 4. Write a new file "report.txt" that lists each student’s name, score, grade and, on the last line, the class average. Below is a draft of the program written by a student. It contains two logical errors. ```python with open('scores.txt', 'r') as f: lines = f.readlines() total = 0 count = 0 high = 0 low = 101 for line in lines: name, sc = line.split(',') score = int(sc) total += score count += 1 if score > high: high = score if score < low: low = score average = total / count with open('report.txt', 'w') as f: for line in lines: name, sc = line.split(',') score = int(sc) if score >= 70: grade = 'A' elif score >= 60: grade = 'B' elif score >= 50: grade = 'C' elif score >= 40: grade = 'D' else: grade = 'F' f.write(f"{name},{score},{grade}\n") f.write(f"Class Average: {average}\n") ``` Answer the following questions:

Question Parts

( a )
Write a correct version of the program that fulfills all four requirements. You may show the algorithm in pseudocode and then provide the final Python code (the code must be syntactically correct).
( b )
Identify the two logical errors in the draft program above and provide the corrected code fragments for each error.
( c )
State the time complexity of the algorithm (in Big‑O notation) in terms of the number of students n, and justify your answer.
( d )
Suggest one modification that would allow the program to also read a second file "extra.txt" containing additional student records and merge them with the original data before processing.

Detailed Solution & Marking Scheme

Get the step-by-step solution, key points required by examiners and detailed marking guidance through the Edcrib AI Tutor.

Reveal Answer

About This Question

This is Neco 2020 Computer Studies Question 8. It is one of the essay questions from the 2020 Neco Computer Studies examination.

The question covers Python programming, File handling, Control structures, Algorithm analysis .

Master the Exam!

You've seen a preview, but there are thousands more questions plus AI tutor to break down complex solutions.

Unlock Full Access Available for Android & Windows
Chat with Support