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
On a rheostat the first terminal is connected to a
Morgarella [4.7K]
On a rheostat the first terminal is connected to a
A ground return path
fined contact
Ceramic heat sink
Bbbbncnennanxkcndkfnrnenwn77819’cjchopeithlps they
5 0
3 years ago
How do we explain the difference between fake news and facts​
Natalija [7]

Answer: it depends if the news is on the news and someone rights an article about it and says some mislead details that's how u know its fake  

Explanation:

3 0
3 years ago
Patient letters created from __________ use structured data and do not require a large amount of typing from the medical assista
umka2103 [35]
Templates I think. not sure
3 0
3 years ago
Tim is in charge of the upcoming interschool baketball tournamnent. He wants to arrange all of the teams and their members in al
zalisa [80]
I think the answer is C.
7 0
3 years ago
If i find an image and copy and paste it into Paint.
Leokris [45]

Answer:

Lossy image formats will remove data during compression as a trade off for lower storage occupation. Lossless data formats will not remove data during compression, resulting in higher quality but also higher storage occupation.

Graphic Artists will almost always use lossless due to it delivering the highest quality image possible.

8 0
3 years ago
Other questions:
  • If you have a 3D printer please show me a vid of you making something because I'm interested in getting one. Ty! Also can someon
    12·1 answer
  • The adjustable contact of a potentiometer is placed at the center of its adjustment. If the total resistance is 5 kOhms, what is
    9·1 answer
  • An administrator running a port scan wants to ensure that no processes are listening on port 23. What state should the port be i
    7·1 answer
  • Whats your favorite sport between these options?
    12·2 answers
  • Mario makes a check payable to "cash," intending to withdraw money from his bank. Kirby takes the check from Mario's notebook an
    10·2 answers
  • Match each type of software license with the appropriate definition.
    11·1 answer
  • For this exercise, you'll use the Rectangle class below (you can assume that the length and width are measured in feet).
    12·1 answer
  • Which is said to be ‘computer on a chip’ (a) Micro processors (b) Microcontrollers (c) Both (c) None of the above
    9·1 answer
  • FREEE POINTS
    8·2 answers
  • 1. If we want define style for an unique element, then which css selector will
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!