Skip to content

Course home

Sign up

Develop code

EasyMediumHard
123456789101112131415
Question 14

A program is written to provide information about environmental noise pollution classifications based on sound intensity decibel (dB) thresholds.

Classifications and decibel lower thresholds (in dB) are stored in parallel arrays. For example, the classification "Moderate" is assigned when the decibel level is from 40 up to but not including 70 dB.

The user can enter an index and the name of the noise classification at that array location is displayed. The user can also enter a decibel level, and the corresponding classification name is displayed.

The initial buggy Python code is structured as follows:

classifications = ["Silent", "Moderate", "Intense", "Hazardous", "Extreme"]
thresholds = [0, 40, 70, 90", 120]
active = true

db_level = 0125

# User enters an index to print classification
index = int(input("Enter index: ")

# ...
classification = classifs[index]
print(int(classification))

# Determine classification from decibel level
if ((db_level < 0) and (db_level > 180)):
    print("Invalid decibel level")
else:
    pointer = 1
    found = False
    while (pointer < len(thresholds) and not found):
        if (db_level < thresholds[pointer]):
            found = True
        elif (thresholds[pointer] > db_level):
            pointer = pointer + 1
    print(classifications[pointer - 2])

Open file Q01.py.

Amend the code to:

  • fix the syntax error on original line 5 thresholds = [0, 40, 70, 90", 120]
  • fix the NameError on original line 6 active = true
  • fix the syntax error on original line 8 db_level = 0125
  • fix the syntax error on original line 15 index = int(input("Enter index: ")
  • fix the NameError on original line 21 classification = classifs[index]
  • fix the ValueError on original line 22 print(int(classification))
  • fix the logic error on original line 26 if ((db_level < 0) and (db_level > 180)):
  • fix the logic error on original line 29 pointer = 1
  • fix the logic error on original line 35 elif (thresholds[pointer] > db_level):
  • fix the logic error on original line 37 print(classifications[pointer - 2])

Do not change the functionality of the given lines of code.

Do not add any additional functionality.

Save your amended code as Q01FINISHED.py

[10]
Markscheme

Develop code Questions

  1. GCSE
  2. /Computer Science
  3. /Develop code

51 exam-style questions on Edexcel GCSE Computer Science Develop code, covering Decomposition and abstraction to solve problems, Read, write, analyse and refine programs, Converting algorithms into programs, Techniques for readable, maintainable code, Identifying and correcting program errors, and Evaluating program fitness and efficiency. Each one has a worked solution and a mark scheme showing where the marks go.

Question bank