Answer:
Program in Python:
file = open("numbers.txt", "r")
count = 0
isum = 0
content = file.readlines()
for nums in content:
num = nums.rstrip('\n').split(" ")
for i in num:
isum= isum + int(i)
count = count + 1
print("Average: "+str(isum/count))
Explanation:
This line opens the file named numbers.txt
file = open("numbers.txt", "r")
This line initializes num to 0
count = 0
This line initializes sum to 0
isum = 0
This line reads the content of the opened file file
content = file.readlines()
This iterates through the content of the file
for nums in content:
This removes trailing new lines and blank spaces from each number
num = nums.rstrip('\n').split(" ")
This also iterates through the content of the file
for i in num:
This calculates the sum of the numbers in the file
isum= isum + int(i)
This counts the numbers in the file
count = count + 1
This calculates and prints the average of the numbers
print("Average: "+str(isum/count))