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
describe a situation in which peer pressure could cause a serious problem for safe driving, and how you could resist the peer pr
Agata [3.3K]
People could pressure you to drink or do drugs etc then drive
you can avoid the problem by staying true to yourself and getting away from those people asap unless they need your help
6 0
3 years ago
Read 2 more answers
Finish the format string to get the output shown below.<br> Day<br> &gt;&gt;&gt;{ v8'_format('Day)
Lorico [155]

In C language, a Format string refers to a string utilized to format output or input. The complete format string is: >>>{% v8'_format('Day)

<h3>What is Format String?</h3>

In computer programming, a format string is a string that is used when formatting the input and output of functions.

It is responsible for the format of the input and output. In C language, it always starts with '%'.

Hence the completed format string will be: >>>{% v8'_format('Day).

Learn more about format strings ta:
brainly.com/question/26000102
#SPJ1

Learn more about Format String at:
brainly.com/question/26000102
#SPJ1

8 0
2 years ago
Why do many administrators choose to use a command line interface on a Linux server?
kozerog [31]
All of the different versions of Linux are the same when using the command line interface.
6 0
3 years ago
Write a recursive decent algorithm for a java while statement, a Javas if statement , an logical/mathematical expression based o
Aleonysh [2.5K]

Using the knowledge in computational language in JAVA it is possible to write a code that recursive decent algorithm for a java while statement, a Javas if statement , an logical/mathematical expression.

<h3>Writting the code in JAVA:</h3>

<em>M ---> { S } ' # '</em>

<em>S ---> I | W | A | P | C | G</em>

<em>I ---> ' [ ' E ' ? ' { S } ' : ' { S } ' ] ' | ' [ ' E ' ? ' { S } ' ] '</em>

<em>W --- > ' { ' E ' ? ' { S } ' } '</em>

<em>A --- > lower-case ' - ' E ' ; '</em>

<em>P --- > ' < ' E ' ; '</em>

<em>G ---> ' ' . ' lower case ' ; '</em>

<em>C ---> ' < ' upper case ' ; '</em>

<em>E ---> T { ( ' + ' | ' - ' ) T }</em>

<em>T ---> U { ( ' * ' | ' / ' | ' % ' ) U }</em>

<em>U ---> F ' ^ ' U | F</em>

<em>F ---> ' ( ' E ' ) ' | lower case | digit</em>

<em>Here "lower-case" stands for a single lower-case letter, and "upper-case" stands for a single upper-case letter. For a more colorful grammar (in a slightly different form), see colorful grammar.</em>

<em>This grammar (and the language it defines) may look a little strange, but it was designed to have only single-character tokens. In particular it doesn't have any reserved words (key words), though in a sense the upper-case letters are reserved.</em>

<em>Just to help with understanding, here is the intuitive meaning of each of the above non-terminals:</em>

<em>SYMBOL MEANING</em>

<em>M Main Program</em>

<em>S Statement</em>

<em>I If-Then-[Else] Statement</em>

<em>W While Statement</em>

<em>A Assignment Statement</em>

<em>P Put or Print (integer)</em>

<em>C Print Character</em>

<em>G Get (integer)</em>

<em>E Expression (logical or arith)</em>

<em>T Termi</em>

<em>U </em>

<em>F Factor</em>

See more about JAVA at brainly.com/question/12975450

#SPJ1

3 0
2 years ago
_______ is a form of crime that targets a computer system to acquire information stored on that computer system, to control the
julia-pushkina [17]

Answer:

Option (A) is the correct answer.

Explanation:

A Computer system can be the target for the crime on which a criminal can acquire the information from the computer system which is stored on it. A Criminal is targeting the system with the help of some software that is entered on the computer system through a network.

In the above question, paragraphs are describing the content related to the crime which targets the computer system. This is a concept of a "computer as target". Hence option "A" is the correct answer while the other is not valid because--

  • Option b suggests the concept behind the storage device of a computer but in the question, it is about the crime of a computer.
  • Option c suggests the concept behind the computer is a criminal but in the question, it is about the crime of a computer.
  • Option d suggests the concept behind the communication of a computer but in the question, it is about the crime of a computer.
4 0
3 years ago
Other questions:
  • NEED ASWERS FAST
    12·1 answer
  • True / False<br> Registers are generally optimized for capacity instead of speed.
    14·1 answer
  • 2. Statement: "I don't agree with you." Nonverbal gesture: Type of gesture:
    6·1 answer
  • Explain what occurs when you synchronize computer and mobile devices.
    5·1 answer
  • If there is a slow internet connection or limited access to certain sites it is often better to _________ a video file before st
    9·2 answers
  • Write an if statement that assigns 100 to x when y is equal to 0.
    7·1 answer
  • In c#, how are parameters passed on?
    15·2 answers
  • Every time a key is pressed on the keyboard, the _______________ chip in the keyboard notices which key has been pressed.
    13·1 answer
  • Which of the following is not an advanced strategy you may use to help you conduct a search on the Internet?
    15·2 answers
  • What type of malware is best known for carrying other malware as a payload?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!