Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given that, when run, the console prints There has been an exception, identify the lines of code by line numbers and/or including the section of

  1. Given that, when run, the console prints There has been an exception, identify the lines of code by line numbers and/or including the section of code that could cause problems and what problems those could be.

This code cannot and will not actually run so you will have to analyze this file by sight

  1. Continuing to consider the code what steps would you take to determine which line (or lines) are causing the problem. Note that this flawed design was chosen for some reason, so you should both consider wholesale redesigns as well as ways to debug it while keeping the general structure as is. Descriptions of your solutions are sufficient but be sure that the description is detailed enough that I understand what your solutions are.image text in transcribed
# Code takes configuration input from a file, user input through the UI, and # live sensor data through a network socket connection. This input is then # combined via a forumla noted within the in-line comments and then written # to a persistent database. assume that any variables used are appropriately scoped and # initialized. def process_datapoint(): try: connectString = # I) Open, read the database connect string from, and close setup.cfg configFile = open("setup.cfg", "r") if configFile.mode == 'r': lineNo = 0 contents = configfile.readlines) while len(connectString) == 0: if configFile[lineNo][0, len(connectstring=")] "connectstring": connectString = configFile[lineNo][len("connectstring=")] configfile.close() # II) Read from the three sensor reading count textboxes sensor1Count = int(sensor1 CountBox.getText() sensor2 Count = int(sensor2 CountBox.getText() sensor 3Count = int(sensor 3CountBox.getText() # III) Grab the next datapoint from the sensor socket representing # the sum of sensor readings since the last readings S = socket.socket() s.connect((sensorAddress, port)) sumOf SensorReadings = int(s.recv(1024)) s.close() # IV) Calculate average of sensor sum over the three sensor reading # counts average = sumOf SensorReadings/(sensorCount + sensor 2 Count + sensor 3Count) # V) Connect to the database specified from the connect string conn = pyodbc.connect(connectString) # VI) Run the sensor data update stored procedure with all data cursor = conn.cursor() cursor.callproc('spUpdateSensorData' (sensor1 Count, sensor2 Count, sensor 3Count, sumOfSensorReadings, average)) # VII) Close the database connection cursor.close() connection.close() except: print("There has been an exception")

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases New Opportunities For Connected Data

Authors: Ian Robinson, Jim Webber, Emil Eifrem

2nd Edition

1491930896, 978-1491930892

More Books

Students also viewed these Databases questions