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
When the narrator of "EPIC 2015" describes the year 2015 as the "worst of
denpristay [2]

Answer:

A. computers will be replaced by new technology

3 0
2 years ago
"You are working on a Debian distribution of Linux. You need to install a package, but you do not want to manually install all t
Stella [2.4K]

Answer:

apt-get

Explanation:

apt-get can be used to manually install a package, without need to manually install all the dependencies for the package.

7 0
3 years ago
Describe the procedure for creating a table or spreadsheet in a presentation slide.
vodomira [7]

Answer:

Select the slide that you want to insert a table on.On the Insert tab, in the Tables group, click Table, and then click Excel Spreadsheet.To add text to a table cell, click the cell, and then enter your text

Explanation:

7 0
2 years ago
Read 2 more answers
.حدد/ي الكيانات في النظام
olasank [31]

Answer:

what

Explanation:

6 0
2 years ago
Read 2 more answers
In which slot is a video card most commonly installed within a laptop?
IgorLugansk [536]

Answer:

<u>PCIe</u> is used for video card installation on Laptop.

Explanation:

Good quality applications, videos and games required graphics card for better results. These card can be installed on laptops, that required some ports.

PCI-e is a slot, that is used in laptop for video or graphic card interface. Video card or graphic card is used to enable high quality video or graphics on Laptop.

PCI- E stand for Peripheral Component Interconnect Express. It work as serial communication interface for high speed device.

7 0
3 years ago
Other questions:
  • Why might your digital footprint be important when you are applying for collage
    13·1 answer
  • What lets you do many things, like write book reports and stories?
    15·1 answer
  • Define function print_popcorn_time() with parameter bag_ounces. If bag_ounces is less than 3, print "Too small". If greater than
    14·1 answer
  • In Microsoft Word, when you highlight existing text you want to replace, you're in
    7·1 answer
  • Where is the worlds biggest cookie​
    7·2 answers
  • What can be defined as in information technology environment?
    14·2 answers
  • You might have trouble interpreting a message if:
    15·1 answer
  • What are some best practices for file management
    8·1 answer
  • The tools, skills, knowledge, and machines created and used by humans is known as.
    13·1 answer
  • Because his father _____ his ten-speed bike away to punish him for his failing grades, the boy sulked for two days.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!