Question: Coding Problem 4.4.2 (External Ies0ulO) Averaging. py 1 Write a function called average file. average file should 2 thave one parameter a filename. 4 The

 Coding Problem 4.4.2 (External Ies0ulO) Averaging. py 1 Write a function

Coding Problem 4.4.2 (External Ies0ulO) Averaging. py 1 Write a function called average file. average file should 2 thave one parameter a filename. 4 The file should have an integer on each line. average file 51#8hould the average ofthese integers. However,-if return 6 Fany of the lines of the file are not integers, 7 +average-file should return the string-"Error reading filel" 9 WRemember, by default, every time you read a line from a 10 file, it's interpreted as a string. 12 13 WAdd your function herel 14 15 16 17 #Below are some lines of code that will test your function. 18 You can change the value of the variable (s) to test your 19 #function with different inputs. 20 # 21+If your function works correctly, this will originally 22 #print: 5.0, then Error reading file! 23 # 24 You can select valid file.txt and invalid file.txt from 25 #the dropdown in the topleft to preview their contents. 26 print(average file("valid file.txt")) 27 print(average file("invalid file.txt")) 29 28

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!