77.6k views
1 vote
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 Elduff
by
8.6k points

1 Answer

3 votes

Answer:

Python 3.X

# Sensor information as a list of tuples

sensor_info = [(0, "4213", "STEM Center"),

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

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

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

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

(5, "Out", "Outside")]

# Create a dictionary to map room numbers to sensor numbers and room descriptions

sensors = {}

for sensor in sensor_info:

sensors[sensor[1]] = (sensor[2], sensor[0])

# Create a list of sensor information from the sensors dictionary using a list comprehension

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

# Create a filter list containing all sensor numbers using a list comprehension

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

def main():

"""Builds data structures required for the program and provides the unit test code"""

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] or item[2] != sensors[item[0]][1]:

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")

print("STEM Center Temperature Project")

print("Mike Murphy")

print()

main_menu = ["1 - Process a new data file",

"2 - Choose units",

"3 - Edit room filter",

"4 - Show summary statistics",

"5 - Show temperature by date and time",

"6 - Show histogram of temperatures",

"7 - Quit"]

for item in main_menu:

print(item)

choice = input("What is your choice? ")

print()

print("Thank you for using the STEM Center Temperature Project")

if __name__ == "__main__":

main()

Python 2.x

# Sensor information as a list of tuples

sensor_info = [(0, "4213", "STEM Center"),

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

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

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

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

(5, "Out", "Outside")]

# Create a dictionary to map room numbers to sensor numbers and room descriptions

sensors = {}

for sensor in sensor_info:

sensors[sensor[1]] = (sensor[2], sensor[0])

# Create a list of sensor information from the sensors dictionary using a list comprehension

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

# Create a filter list containing all sensor numbers using a list comprehension

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

def main():

"""Builds data structures required for the program and provides the unit test code"""

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] or item[2] != sensors[item[0]][1]:

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"

print "STEM Center Temperature Project"

print "Mike Murphy"

print

main_menu = ["1 - Process a new data file",

"2 - Choose units",

"3 - Edit room filter",

"4 - Show summary statistics",

"5 - Show temperature by date and time",

"6 - Show histogram of temperatures",

"7 - Quit"]

for item in main_menu:

print item

choice = raw_input("What is your choice? ")

print

print "Thank you for using the STEM Center Temperature Project"

if __name__ == "__main__":

main()

Step-by-step explanation:

Please help write a python code of Creating a Sensor List and Filter List. It's due-example-1
User Smakus
by
8.2k points

Related questions

1 answer
3 votes
65.7k views