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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started