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
The phrase has become an Internet buzz word. It refers to a top-level domain name for communications organizations.TrueFalse
Tom [10]

Answer:

True

Explanation:

Top-level domain name (TDN) is one of the domain name at the highest position in the hierarchy of domain name system. TDN are installed in the root zone of the domain. An example of these domain names are the "com", "org", "net" etc, of a website's name. Organisations like the ICANN are in charge of managing the root zone for the top level domains are installed in.

6 0
3 years ago
A company is looking for an employee to help organize customer information for the sales team. Which computer field includes thi
slavikrds [6]

Answer:

A

Explanation:

security organises the customer's info online and in person for the sales team.

4 0
2 years ago
Read 2 more answers
Joshua is creating his résumé, in which section will he add projects and trainings he was involved in?
enot [183]
You put it in the skills and certifications section
4 0
3 years ago
When assembling a desktop computer you should always install the drives before the motherboard?
s2008m [1.1K]
Yes you should install drives first
8 0
3 years ago
Date
IRISSAK [1]

Answer:

computer is an electronic machine that accept raw data ,process and then give result. it's uses:

It is used for storing data and information.

5 0
3 years ago
Other questions:
  • business owners and managers may first balk at the idea of mobile officer workers because there may appear to be a lack of ___ w
    9·1 answer
  • Submit your 300-word essay describing the equipment usedI in a well-equipped studio’s audio department and the training and expe
    8·2 answers
  • An essential skill today is knowing how to cite sources properly. Creative Commons has a system of licenses and tools for creato
    11·1 answer
  • A girl scout troop with 10 girl scouts and 2 leaders goes on a hike. When the path narrows, they must walk in single file with a
    12·1 answer
  • 3. Before you get ready to go diving, you want to explore the area. You see a small snowpack across a small bridge, a short walk
    11·1 answer
  • A technician wants to consolidate and log specific alerts from network devices into a database so maintenance tasks and potentia
    11·1 answer
  • Probability can be used to determine the likelihood of specific __________
    6·2 answers
  • HELP PLS!!! In a presentation, what is layout?
    10·2 answers
  • Which type of document should Omar print?
    5·2 answers
  • Using C, Write a program that reads a series of strings from standard input and prints only those strings beginning with the let
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!