65.7k views
3 votes
Please help write a python code of Creating a Sensor List and Filter List. It's due on May 7th.

Please help write a python code of Creating a Sensor List and Filter List. It's due-example-1
Please help write a python code of Creating a Sensor List and Filter List. It's due-example-1
Please help write a python code of Creating a Sensor List and Filter List. It's due-example-2
Please help write a python code of Creating a Sensor List and Filter List. It's due-example-3
Please help write a python code of Creating a Sensor List and Filter List. It's due-example-4
Please help write a python code of Creating a Sensor List and Filter List. It's due-example-5
User Ashmir
by
7.7k points

1 Answer

5 votes

Answer:

Python 2.x

def main():

"""Builds data structures required for the program

and provides the unit test code"""

# To Create a dictionary of sensors

sensors = {"4213": ("STEM Center", 0),

"4201": ("Foundations Lab", 1),

"4204": ("CS Lab", 2),

"4218": ("Workshop Room", 3),

"4205": ("Tiled Room", 4),

"Out": ("Outside", 5)}

# To Create a list of sensors

sensor_list = [(room, sensors[room][0], sensors[room][1]) for room in sensors]

# To Create a list of filters

filter_list = [sensors[room][1] for room in sensors]

# Unit tests

print("Testing sensors: ")

if sensors["4213"][0] == "STEM Center" and sensors["Out"][1] == 5:

print("Pass")

else:

print("Fail")

print("Testing sensor_list length:")

if len(sensor_list) == 6:

print("Pass")

else:

print("Fail")

print("Testing sensor_list content:")

for item in sensor_list:

if item[1] != sensors[item[0]][0]:

print("Fail")

break

else:

print("Pass")

print("Testing filter_list length:")

if len(filter_list) == 6:

print("Pass")

else:

print("Fail")

print("Testing filter_list content:")

if sum(filter_list) == 15:

print("Pass")

else:

print("Fail")

main()

Step-by-step explanation:

User Allyn
by
8.4k points