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
Write pseudo code that performs the following: Ask a user to enter a number. If the
CaHeK987 [17]
Answer:
BEGIN
INPUT N
IF N>0 AND N<10 THEN
OUTPUT "blue"
ELSE
IF N>10 AND N<20 THEN
OUTPUT "red"
ELSE
IF N>20 AND N<30 THEN
OUTPUT "green"
ELSE
OUTPUT "It is not a correct color option"
ENDIF
END.

Explanation:

3 0
2 years ago
Bill needs to make a presentation in which he has to represent data in the form of a pyramid. Which feature or menu option of a
andreyandreev [35.5K]

Answer:If you need to use arrows in a chart, which feature or menu option of a word processing program would you use?

A.  

Picture

B.  

Shapes

C.  

Clip Art

D.  

SmartArt

E.  

Charts

Explanation:

7 0
3 years ago
I really need the answer now!!
guajiro [1.7K]

Answer:

3. B.

4. B.

5. B.

6. C.

7. D.

8. C.

9. C.

10. D.

Explanation:

I hope I helped you.

4 0
2 years ago
The "edit" command must allow the user to find a record in the list by director. If there are multiple records with the same dir
sveticcg [70]

Answer:

To allow user to assign rating

Explanation:

The basic function of “rate” command is to give opportunity to the user to assign a value to a song from the range of 1 – 5.

In the range, the value of 1 indicates the lowest rating, while value of 5 is the highest rating that can be obtained.

Any previous ratings are then replaced by the new rating assigned from the range of 1 – 5.

7 0
3 years ago
Can you help please ill give branilist
konstantin123 [22]

HTML uses tags to help the computer know what different pieces of content in the web page actually are. Right now we've only learned how to tell the computer that some text is a paragraph, or that part of your website is the body. We've already seen how that affects the way our web pages look and are structured.

(I don't know how it should be organized, but hope this helped)

3 0
2 years ago
Other questions:
  • If you write a toString method to display the contents of an object, object1, for a class, Class1, then the following two statem
    14·1 answer
  • e do loop differs from the while loop in that a. the while loop will always execute the body of the loop at least once b. the do
    9·1 answer
  • Which types of operating systems execute program independent of the users and generate output within a specific amount of time?
    5·1 answer
  • You are a network technician for a small corporate network. It's been decided that the office needs a wireless network for emplo
    6·1 answer
  • Write a parent program to fork(2) n processes where n is passed tothe program on the command line, and n can be from 1 to 10. Al
    12·1 answer
  • Describe at least two other companies that are direct or indirect competitors to your company. Explain how you will differentiat
    15·1 answer
  • During a test, it is generally best to: A. answer all questions in order B answer the essay questions first C. answer the least
    7·2 answers
  • How do you give brianliest
    13·1 answer
  • Which of the following statements best compares and contrasts hot and cold type?
    12·1 answer
  • 1) "Information systems are revolutionizing the way businesses function in the 21st century," Do you agree or disagree with this
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!