Respuesta :
Answer:
Following is the program code as required.
Comments are given inside the code.
Explanation:
(=> Defining the main function)
def main():
(=> Getting input from user)
file = input("What is name of file?")
(=>Storing text from file in variable data )
data = open(file, "r")
(=> read the file and then split it)
info = data.read().split()
(=> Generating array named numbers)
numbers = []
for line in info:
(=>numbers will be appended from in format to list format)
numbers.append(int(line))
data.close()
(=> Average will be found by dividing sum of numbers to length of array)
avg = float(sum(numbers))/len(numbers)
(=> Printing calculation of average)
print("Calculated average is",avg)
main()
i hope it will help you!
The program is an illustration of file manipulations
File manipulations are used to read from and write into a file
The program in Python where comments are used to explain each line is as follows:
#This gets input for the filename
file = input("Filename: ")
#This initializes the sum and count to 0
sum = 0; count = 0
#This opens the file
fopen = open(file, "r")
#This splits the contents of the file
content = fopen.read().split()
#This iterates through the content of the file
for line in content:
#This calculates the sum of the numbers
sum +=int(line)
#This keeps count of the numbers
count+=1
#This closes the file
fopen.close()
#This calculates the average
average = float(sum)/count
#This prints the calculated average
print("Average:",average)
Read more about similar programs at:
https://brainly.com/question/20595337