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
Masteriza [31]
3 years ago
7

Write a function called st_dev. St_dev should have one #parameter, a filename. The file will contain one integer on #each line.

The function should return the population standard #deviation of those numbers.
Computers and Technology
1 answer:
kodGreya [7K]3 years ago
6 0

Answer:

  1. import statistics
  2. def st_dev(file_name):
  3.    with open(file_name) as file:
  4.        data = file.readlines()
  5.        numList = []
  6.        for x in data:
  7.            numList.append(int(x))
  8.        
  9.        return statistics.pstdev(numList)
  10. print(st_dev("text1.txt"))

Explanation:

The solution code is written using Python.

To ease the calculation task, we can import Python statistics module to use the pstdev method to calculate the population standard deviation of a list of numbers (Line 1).

Next, create a st_dev function that take single argument file_name (Line 3). In the function, it will open the input file and read the data line by line (Line 4-5). Create a for loop to traverse through each line of the data which is an integer and append it to numList (Line 7-8). We can pass the numList to pstdev method (Line 10) and return the resulting standard deviation value as output.

We test the function by passing a file which hold a list of integer values in each line (Line 12).

8

9

12

11

21

15

16

10

7

13

And the output we shall get is 4.019950248448356

You might be interested in
Given the declarations struct BrandInfo { string company; string model; }; struct DiskType { BrandInfo brand; float capacity; };
Nonamiya [84]

Answer:

Type of myDisk.brand is BrandInfo.

Explanation:

4 0
3 years ago
In this chapter, you saw an example of how to write an algorithm that determines whether a number is even or odd. Write a progra
vagabundo [1.1K]

Answer:

// Program is written in Java Programming Language

// Comments are used for explanatory purpose

// Program starts here

public class RandomOddEve {

/** Main Method */

public static void main(String[] args) {

int[] nums = new int[100]; // Declare an array of 100 integers

// Store the counts of 100 random numbers

for (int i = 1; i <= 100; i++) {

nums[(int)(Math.random() * 10)]++;

}

int odd = 0, even = 0; // declare even and odd variables to 0, respectively

// Both variables will serve a counters

// Check for odd and even numbers

for(int I = 0; I<100; I++)

{

if (nums[I]%2 == 0) {// Even number.

even++;

}

else // Odd number.

{

odd++;

}

}

//.Print Results

System.out.print("Odd number = "+odd);

System.out.print("Even number = "+even);

}

8 0
3 years ago
Read 2 more answers
What helps companies and organizations to target masses of people, provide 24/7 services, and deliver better marketing in a chea
Sever21 [200]
The money their making
6 0
3 years ago
Do all light bulbs server a practical purpose?
Greeley [361]

Answer:

A light bulb produces light from electricity

6 0
3 years ago
1:A presentation program which is developed by Microsoft
LekaFEV [45]
Option 3: PowerPoint.
4 0
2 years ago
Read 2 more answers
Other questions:
  • Using caller id is part of which step in an effective time management plan
    10·1 answer
  • True or false the primary advantage of the worksheet is the ability to solve numerical problems quickly and accurately
    11·1 answer
  • Why isn't my rank move from ambitious to virsto i met all the requirements
    8·2 answers
  • 2. What's the keyboard command that will allow you to "copy" text?
    8·2 answers
  • Samantha plans an investigation in which she will study a population of animals. Which of these answers best describes the focus
    8·1 answer
  • If you do not want to keep a change made by the autocorrect feature, you can click the ____ button on the auto correction option
    12·1 answer
  • Which magazine introduced the first microcomputer kit for the mits altair in its january 1975 issue?
    8·1 answer
  • Portable Document Format (PDF) is a file format that provides an electronic image of a document and can be viewed, printed, and
    12·2 answers
  • Anyone has any ideas for a gaming setup i can buy for christmas. Something with high framing rates (monitor included) for about
    15·1 answer
  • What option in the zone aging/scavenging properties dialog box will prevent dns record time stamps from being updated too often?
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!