Gce Model Questions Vol1 2019 Computer Studies Question 8

Practice essay / theory question 8 from the 2019 Gce Model Questions Vol1 Computer Studies examination. This question covers Python programming, File handling, Lists and sorting, Algorithms (median, mode), Complexity analysis .

Gce Model Questions Vol1 2019 Computer Studies Essay / Theory
Topics: Python programming File handling Lists and sorting Algorithms (median, mode) Complexity analysis
Question 8 GCE_MODEL_QUESTIONS_VOL1 • 2019 • COMPUTER_STUDIES • essay

Consider the following Python program that is intended to read a text file **data.txt** (containing one integer per line), store the integers in a list, compute the median of the data, and write the sorted list to a new file **sorted.txt**. The program, however, contains several mistakes that prevent it from working correctly. ```python import sys def median(nums): nums.sort() n = len(nums) if n % 2 = 0: return (nums[n/2] + nums[n/2 + 1]) / 2 else: return nums[(n+1)/2] file = open('data.txt', 'r') lines = file.readlines() numbers = [] for line in lines: numbers.append(int(line)) file.close() print('The median is', median(numbers)) sorted_file = open('sorted.txt', 'w') sorted_file.write(numbers) sorted_file.close() ```

Question Parts

( a )
Identify and explain three logical or syntactic errors in the program that would prevent it from producing the correct median and writing the sorted list.

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 Gce Model Questions Vol1 2019 Computer Studies Question 8. It is one of the essay questions from the 2019 Gce Model Questions Vol1 Computer Studies examination.

The question covers Python programming, File handling, Lists and sorting, Algorithms (median, mode), Complexity 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