Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed
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

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

DB2 11 The Ultimate Database For Cloud Analytics And Mobile

Authors: John Campbell, Chris Crone, Gareth Jones, Surekha Parekh, Jay Yothers

1st Edition

1583474013, 978-1583474013

More Books

Students also viewed these Databases questions

Question

=+you think is being taxed when more money is printed? Why?

Answered: 1 week ago