Question: I need a code check for my python programming Average of Numbers Assume that a file containing a series of integers is named numbers.dat and

I need a code check for my python programming

Average of Numbers Assume that a file containing a series of integers is named numbers.dat and exists on the computers disk. Design a program that calculates the average of all the numbers stored in the file.

def main():

total = 0.0

count = 0

#open file with numbers to be averaged

#assign to variable

random_numbers_file = open('numbers.dat,'r')

#iterate for loop

for all lines in 'file' for line in random_numbers_file:

number = float(line)

count += 1

total += number average = total / count

print("The average of all the numbers found in 'numbers.txt' is:", format(average,'.2f'))

main()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!