Neco 2021 Computer Studies Question 8

Practice essay / theory question 8 from the 2021 Neco Computer Studies examination. This question covers Python programming, Algorithms, Error detection and correction .

Neco 2021 Computer Studies Essay / Theory
Topics: Python programming Algorithms Error detection and correction
Question 8 NECO • 2021 • COMPUTER_STUDIES • essay

A teacher asks students to develop a Python program that processes a list of integers according to the following specification: 1. Remove all duplicate values from the list. 2. Sort the remaining distinct numbers in descending order. 3. Print the second largest number. If the list contains fewer than two distinct numbers, the program should output the message "Insufficient data". Answer the questions below.

Question Parts

( a )
Write a complete Python function named `second_largest(nums)` that implements the specification. The function should return the required integer or the string "Insufficient data".
( b )
The following code was submitted by a student but fails to meet the specification. Identify **three** distinct errors (syntax, logical or runtime) and provide a corrected version of the code. ```python def second_largest(nums): uniq = list(set(nums)) uniq.sort() if len(uniq) = 1: return "Insufficient data" else: return uniq[-2] print(second_largest([4, 2, 5, 5, 3])) ```
( c )
State the time‑complexity of the algorithm you wrote in part (a) using Big‑O notation and briefly justify your answer.

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 2021 Computer Studies Question 8. It is one of the essay questions from the 2021 Neco Computer Studies examination.

The question covers Python programming, Algorithms, Error detection and correction .

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