Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write the following code in python 3.2+. Recursive function prefered. Thank you!

ID: 3832374 • Letter: W

Question

write the following code in python 3.2+. Recursive function prefered. Thank you!

The Artesian Corporation manufactures electronic devices that activate automatic airbags in passenger vehicles. They store their quality control testing data in text files where each line of the file contains two values, a String representing the ID of an individual electronic device and an Integer (in the range 0 - 100) representing the score the device received during a quality control test. There are multiple scores for each device in the file. Define a function named q10 () that accepts a String as a parameter which the filename. The q10 () function will read the contents of the file and determine the average score for each electronic device identified storing this information in a Dictionary using the device name as the key and average score as the corresponding value. The q10 () function should work correctly regardless of the number of devices or entries in the file.

Explanation / Answer

Q10(filename) :

Mydict={}

File=open(filename, 'r')

For line in file:

Line=line.strip().split()

If line[0] not in mydict.keys():

Mydict[ line[0]]= line[1]

Else:

  mydict[line[0] ] = mydict[line[0] ] +line[1]