Write a program that lets the user enter in a file name (numbers.txt) to read, keeps a running total of how many numbers are in the file, calculates and prints the average of all the numbers in the file. This must use a while loop that ends when end of file is reached. This program should include FileNotFoundError and ValueError exception handling. Sample output: Enter file name: numbers.txt There were 20 numbers in the file. The average is 4.35

Respuesta :

Answer:

Check the explanation

Explanation:

The code will be

name=input('Enter file name:')

ls=open(name,'r').read().split('\n')

count=0;sums=0

for i in range(ls):

sums+=int(i)

count+=1

print('There were {} numbers in the file'.format(count))

print('The average is {}'.format(sums/count))

The output is

Ver imagen temmydbrain