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]
4 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]4 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
Explain briely what this statement mean.<br>"A byte is equivalent to a character"<br>​
dedylja [7]

To put it briefly, a byte is equivalent to a <em>character</em> in that it encodes a single character, being this in the form of a<u> letter, number, or symbol.</u>

A byte is the smallest unit of storage memory on any modern computer. This byte is commonly made up of<u> eight bits</u>, a combination of binary digits used to represent data. The hierarchy of computer memory is as follows:

  • 1 byte
  • 1 kilobyte
  • 1 megabyte
  • 1 gigabyte
  • 1 terabyte

The statement "<em>A byte is equivalent to a character</em>" is quite literal in its meaning given that through the use of the bits that comprise it, a byte is used to represent and store the data for a single character of text, being that a <u>letter, number or at times a symbol.</u>

<u />

To learn more:

brainly.com/question/13188094?referrer=searchResults

3 0
3 years ago
Which name is a default library name in Windows 7?
Blizzard [7]

Answer:

In Windows 7, there are four default libraries: Documents, Music, Pictures, and Videos. All the default libraries include two standard folders: the user folder specific to each library and the public folder specific to it.

Explanation:

6 0
3 years ago
State Newton’s second law of motion. Show that Newton’s first and third laws of motion are contained in the second law​
mixer [17]

Answer:

Every physics student learns Newton's three laws of motion. It's tempting to consider that these are three separate and independent laws. That's not so. Both the first and third laws may be mathematically derived from the second law, as we will show.

The fact that the first law may be derived from the second has long been known. The second law,Fnet=ma, tells us that the net (vector sum) of all forces acting on a body is equal to the product of the body's mass and its vector acceleration. When the acceleration is zero, the net force must be zero. This is exactly the content of the first law.

Let's first consider the case of two bodies in contact. Each exerts a force on the other at the interface, or point of contact, where the bodies touch. If that point or interface is treated as a "body" of mass zero, then Newton's second law tells us thatFnet=0a, soFnet= 0. So the net force on a body of zero mass is always zero, whatever forces act upon it. Therefore if only two forces act on a body, they must add to zero, and therefore must be equal size and oppositely directed. This establishes Newton's third law.

Explanation:

Hope this helps

6 0
3 years ago
Write a 10 sentence paragraph about george washington and abraham lincoln and no plagiarism
Mamont248 [21]
10 sentence paragraph about George Washington and Abraham Lincoln and no playgiarism
8 0
3 years ago
Read 2 more answers
When a linke chain contain nodes that reference both the next node and the previous node it is called a(n)
ch4aika [34]
A. Two way linked chain
4 0
3 years ago
Other questions:
  • Austin works as a department head and frequently uses presentations to deliver information to his staff. He relies heavily on pr
    5·2 answers
  • Datta Computer Systems is considering a project that has the following cash flow data. What is the project's IRR? Note that a pr
    10·1 answer
  • What is the line tool used for in photoshop
    6·1 answer
  • You share a number of files from your computer, and you've received a number of calls from users who say they can't connect to t
    5·1 answer
  • Which two pieces of information must be provided when saving a file for the first time in Wordpad?____.
    8·1 answer
  • A software EULA is an agreement related to which of the following?
    11·2 answers
  • AYYOOOO CAN YOU HELP A GIRL OUUTT???
    11·1 answer
  • What is the georgia connections academy administrative password? i want to install something.
    5·1 answer
  • Select the correct text in the passage.
    15·1 answer
  • You have a filtered dataset for Customer Sales with some null value rows. You want to remove these rows completely. How will you
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!