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
Savatey [412]
3 years ago
15

Define a function below called average_num_in_file. The function takes one argument: the name of a file full of numbers. Complet

e the function so that it opens the file and returns the average of the numbers in the file. Here is an example input file from the static test case if you want to test from the interpreter: canned_file.txt
Computers and Technology
1 answer:
Nookie1986 [14]3 years ago
7 0

Answer:

  1. def average_num_in_file(fileName):
  2.    with open(fileName) as file:
  3.        rows = file.readlines()
  4.        sum = 0
  5.        count = 0
  6.        for x in rows:
  7.            sum += float(x)  
  8.            count += 1
  9.        average = sum / count  
  10.    return average  
  11. print(average_num_in_file("cans.txt"))

Explanation:

The solution code is written in Python 3.

Firstly create a function that take one parameter, fileName (Line 1).

Open the file stream and use readlines method to read the data from the file (Line 2-3). Create variable sum and count to tract the total of the number from text files and number of data from the file (Line 5-6). Use a for loop to loop over each row of the read data and add the current value of each row to sum and increment the count by one (Line 7-9).

After the loop, calculate the average (Line 11) and return the result (Line 12).

At last, we can test the function by passing the cans.txt as argument (Line 14).

You might be interested in
A ________ is a device used to illegally capture the data stored on the magnetic stripe of an ATM card, credit card, or debit ca
Ksenya-84 [330]

Answer:

skimmer

Explanation:

8 0
3 years ago
Using these Web sites for guidance, write a definition in your own words for five of the terms listed below.
Feliz [49]

Answer:

Gigabyte: Unit of measurement, is 10^9 bytes.

Intranet: Network that is used for sharing info, and other services.

Pixel: Creates a image, it is the smallest element on a display on a device.

Modem: Converts signals produced by a computer or another type of device.

Digital: Problem solving by any capable class device.

Explanation:

Short and simple.

7 0
3 years ago
Which Windows installation method requires that you manually rename computers after the installation?​
levacccp [35]

Answer:

Command line

Explanation:

  • After installation of the machine one needs to manually rename the computer. This can be done through the start then settings, then system, and select rename the PC in the right-hand side column.
3 0
3 years ago
Are used in the Excel application to create calculations
OlgaM077 [116]

Answer:

I think the answer is formulas

6 0
3 years ago
Read 2 more answers
If you need to provide a storage server with fault tolerance through the use of multiple paths between the server and the actual
yan [13]

Answer:

The correct answer to the following question will be "Multipath I/O ".

Explanation:

Multipath I/O going to minimize the impact of a failure of either the host network interface by offering an alternative access route through storage media as well as a Windows OS.

  • It offers the possibility for someone like you to support high accessibility and significantly improve efficiency based on your SAN setup.
  • Offer valuable even fault resistance to a terminal server by using different objectives or paths.

So, you should install this Multipath I/O.

3 0
3 years ago
Other questions:
  • Determine the number of bytes necessary to store an uncompressed binary image of size 4000 × 3000 pixels.
    9·1 answer
  • What is life all about?
    15·2 answers
  • The ____ shortcut keys remove character formatting. (points : 2) ctrl 0 (zero) ctrl i ctrl spacebar ctrl u
    8·2 answers
  • Why did Hunter gatherers moved into the<br>America's?​
    8·1 answer
  • Eight what makes one character
    14·1 answer
  • What are cell phones used for?
    8·2 answers
  • What are the OSHA construction standards also called ?
    10·1 answer
  • Is a pocket watch consider a computer
    15·1 answer
  • Explain why you do not need expensive equipment to take pictures or record video?
    7·2 answers
  • Explain briefly how learning how to follow can make a person a good leader
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!