[Solved] COMP1012 Lab4

$25

File Name: COMP1012_Lab4.zip
File Size: 122.46 KB

SKU: [Solved] COMP1012 Lab4 Category: Tag:
5/5 - (1 vote)

Exercise 1: Standard deviation

Open the file lab4.csv. This file has 3 numbers per-line, separated by commas.

Calculate the mean and standard deviation of each column of the file, using the formula:

=i=1N(xix)2N1

Where is standard deviation, x is the mean of the dataset, N is the number of elements in the dataset, and xi is an element of the dataset at spot i.

You will need to:

  1. open the file.
  2. Initialize 3 list accumulators.
  3. Iterate over the lines of the file in a for loop and accumulate the values in the columns.
  4. Compute the average (either do this inside the loop with a running sum or use the sum function on your lists).

Once you have the mean x, calculate the standard deviation using a second for loop.

Your output should look like:

The mean of column 1 is 50.30, and the standard deviation is 28.81The mean of column 2 is 499.79, and the standard deviation is 290.16The mean of column 3 is 5011.12, and the standard deviation is 2874.15

Nested 🐤 lists

As an extra exercise, consider how to write this using nested lists. You may need to use the range function if you choose to solve this problem.

Exercise 2: Standard deviations from the mean

Add to your program from the previous part to ask for numerical input from the user. Find how many standard deviations from the mean the input is.

The formula for deviations from the mean is:

deviationsFromMean=|xx|

Where is the standard deviation, x is the mean of the dataset, and x is the data the user provided.

Give me a number : > 50This number is 0000.0104 standard deviations from the mean for column 1.This number is 0001.5501 standard deviations from the mean for column 2.This number is 0001.7261 standard deviations from the mean for column 3.

Nested 🐤 lists

If you did the extra exercise for above, add to this part an option for the user to choose which column the standard deviation is calculated for.

Optional exercises

Basic if usage

Change your above code. Use an if statement to remove negative numbers, creating a standard deviation with only positive numbers (which we will define as greater than or equal to 0).

Evens only

Change your if statement to only accept even numbers and positive. The data are decimal numbers, so we will define even as The 1s place is even.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] COMP1012 Lab4
$25