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
OSHA requires training for employees on the hazards to which they will be exposed.
Sedaia [141]

A, OSHA does require training for employees on the hazards to which they will be exposed.


3 0
4 years ago
Read 2 more answers
Question 2 (2 points)
swat32

I beleive all of the above for question one

4 0
3 years ago
All computers can support multiple internal hard drives. <br><br> a. True <br><br> b. False
lara31 [8.8K]
False.  Some can, but some do not have space for them.  Please mark Brainliest!!!
5 0
3 years ago
Points!!!!!!!! pls help
siniylev [52]
D. Rasterize

This answer makes the most since
7 0
3 years ago
Read 2 more answers
What are the controls in the Capture panel? Define each controls
MArishka [77]

Answer:

.............

........

8 0
3 years ago
Other questions:
  • Write a program that sorts a vector of names alphabetically using the selection sort and then searches the vector for a specific
    7·1 answer
  • The main disadvantage of using this device is its negative impact on network performance,resulting from the fact that any incomi
    10·1 answer
  • PowerPoint provides a wide variety of predefined shapes that can add visual insert to a slide true or false
    10·2 answers
  • Unemployment can be viewed as
    14·1 answer
  • The acronym pies is used to describe improvised explosive devices (ied) components. pies stands for:
    13·2 answers
  • Join zoom meet <br>id=547 458 9345<br>pw=sencHURI​
    8·2 answers
  • HELP AASAP BRAINLIEST JUST HELP
    13·1 answer
  • Who plays xbox one offline and knows some multiplayer games that can be played offline.
    15·2 answers
  • What are the fundamental activities that are common to all software processes?
    9·1 answer
  • Có n chiếc kẹo và m em bé. Hãy viết chương trình nhập vào hai số nguyên dương n, m và kiểm tra n chiếc kẹo có chia đều được cho
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!