1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
WITCHER [35]
3 years ago
15

Assume that a file containing a series of integers is named numbers.txt. Write a program that calculates the average of all the

numbers stored in the file. The input file may have numbers all on one line or several lines or one number on each line.
Computers and Technology
1 answer:
Anna [14]3 years ago
8 0

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))

You might be interested in
Find the greatest common factor of 48 and 36.​
gregori [183]

Answer:

Hello, The prime factorization of 48 is: 2 x 2 x 2 x 2 x 3. And The  prime factorization of 36 is: 2 x 2 x 3 x 3.

Explanation:

The prime factors and multiplicities 48 and 36 have in common are: 2 x 2 x 3.

2 x 2 x 3 is the "GCF" of 48 and 36.

"GCF"(48,36) = 12.

7 0
3 years ago
Go to the Creamy Ice Corporation passage on the next page. Insert the trademark sign after the word “Corporation'' in the first
GuDViN [60]

Answer:

v

Explanation:

because it is

5 0
4 years ago
Would the book values of microsoft corporation's fixed assets normally approximate their fair market values?
Pepsi [2]
As in official Microsoft courseware? If so, then Yes, they will be the same price no matter where you purchase them.
7 0
3 years ago
The _____ is the area in Microsoft Excel where you can perform file commands such as Save, Open, and Print
Arlecino [84]
The BACKSTAGE VIEW is the area in Microsoft where one can perform file commands such as save, open and print.
The backstage view can be found under the file tab in the excel window. It has many options available and they include the following:info, new, open, save, save as, print, share, export and close. These options give the user the opportunity to perform desired functions on their workbook.
8 0
4 years ago
Which of the following reflects the order of operations
lorasvet [3.4K]

Answer: PEMDAS

Parenthesis, Exponents, Multiplication, Division, Addition, Subtraction

Explanation:

3 0
3 years ago
Read 2 more answers
Other questions:
  • A digital footprint is all of the information on-line about a person posted by that person or others, ____________. intentionall
    14·1 answer
  • What considerations have to be kept in mind with JPEG
    10·1 answer
  • What would be a situation in which you could use an Excel chart to present your data?
    11·2 answers
  • Where do you access the status report of an assigned task that is open?
    12·2 answers
  • Before you give your presentation to an audience, you should make sure that your ideas are organized in a clear and meaningful w
    8·2 answers
  • The (X , y) coordinates of a certain object as a function of time' are given by Write a program to determine the time at which t
    6·1 answer
  • Which area of a magazine cover is often important for those shops and stalls that cannot display the entire cover page on a stan
    15·1 answer
  • Select the education and qualifications that are most helpful for Insurance Services careers. Check all that apply.
    14·2 answers
  • Which is an appropriate strategy for using a workplace blog?
    9·1 answer
  • Why must the image be reduced when the field of view is widened to take in more of the scene?
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!