Question: This language is python and I have no idea where to start. Since it requires the average, you should take all integers into consideration. As
This language is python and I have no idea where to start. Since it requires the average, you should take all integers into consideration. As for valid or invalid, I'm going to assume valid files because the instructions didn't state otherwise.
#Write a function called average_file. average_file should #have one parameter: a filename. # #The file should have an integer on each line. average_file #should return the average of these integers. However, if #any of the lines of the file are _not_ integers, #average_file should return the string "Error reading file!" # #Remember, by default, every time you read a line from a #file, it's interpreted as a string.
#Add your function here!
#Below are some lines of code that will test your function. #You can change the value of the variable(s) to test your #function with different inputs. # #If your function works correctly, this will originally #print: 5.0, then Error reading file! # #You can select valid_file.txt and invalid_file.txt from #the dropdown in the top left to preview their contents. print(average_file("valid_file.txt")) print(average_file("invalid_file.txt"))
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
