#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ ENGG1811 Lecture Nested for-loop """ # Create a list of list temp_list = [[ 0.3, 0.4, 0.5, 0.5, 0.1, 0.8, 0.8, 0.5, 0.0, 0.7], [ 0.2, 0.4, 0.8, 0.4, 0.8, 1.8, 0.9, 0.1, 1.4, 1.7], [ 1.1, 0.1, 0.8, 0.9, 0.5, 0.3, 0.2, 0.2, 1.1, 0.4], [ 0.4, 0.7, 0.6, 0.6, 0.4, 0.4, 0.5, 0.0, 0.1, 0.2], [ 0.2, 0.1, 0.9, 0.9, 0.3, 0.5, 0.4, 0.7, 0.2, 0.7]] # Each list contains data from a thermometer # The threshold is 1 # Want to see the number of data points exceeding the threshold for each # thermometer threshold = 1 # %% Development step 1: for thermometer_readings in temp_list: # This is to show that thermometer is a list print(thermometer_readings) # %% Development step 2: # Use a list within temp_list to count the number of times the thershold is # exceeded thermometer_readings = temp_list[2] count = 0 # number of times that the threshold is exceeded for temp in thermometer_readings: if temp > threshold: # print(temp) count += 1 print('In ',thermometer_readings,':') print('the number of times exceeding threshold =',count) # %% Development step 3: # Merge the code developed before # count_exceeding is a list storing the number of times that the reading # from therometer has exceed the threshold # %% Development step 3: count_exceeding = [] # count_exceeding.append(count) print('Number of times each thermometer has exceeded the threshold', count_exceeding)