Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke

1st Edition

0130086509, 978-0130086501

More Books

Students also viewed these Databases questions