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:
thresholds = [0, 40, 70, 90", 120]active = truedb_level = 0125index = int(input("Enter index: ")classification = classifs[index]print(int(classification))if ((db_level < 0) and (db_level > 180)):pointer = 1elif (thresholds[pointer] > db_level):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
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.