Structured programming and subroutines (procedures and functions)

EasyMediumHard
1234567891011121314
Question 5
Hard

Write a subroutine in Python called evaluateAirQuality that will count the number of times the string "Hazardous" appears in a grid of air quality readings.

The subroutine should:

  • take a 2D array called airSensorGrid as a parameter
  • count the number of times "Hazardous" appears in the airSensorGrid array
  • output the word "Evacuate" if there are exactly eight "Hazardous" items in the array
  • output the total number of "Hazardous" items if there are fewer than eight.

You must write your own counting routine utilizing nested loops and not use any built-in count functions or methods (such as .count()) that might be available in Python.

You should use indentation as appropriate, meaningful variable name(s), and Python syntax in your answer.

Figure 1

012
0SafeHazardousSafe
1HazardousWarningHazardous
2SafeHazardousHazardous
[8]

Structured programming and subroutines (procedures and functions) Questions

  1. GCSE
  2. /Computer Science
  3. /Structured programming and subroutines (procedures and functions)