Data Analysis with Python Projects - Mean-Variance-Standard Deviation Calculator

Tell us what’s happening:

Describe your issue in detail here.
showing some failure = 1

Your code so far

import numpy as np

def calculate(list):
if len(list) != 9:
return “List must contain nine numbers.”

try:
    array = np.array(list)
    matrix = np.reshape(array, (3, 3))

    mean_ax_1 = np.mean(matrix, axis=0).tolist()
    mean_ax_2 = np.mean(matrix, axis=1).tolist()
    mean_flat = np.mean(list)

    var_ax_1 = np.var(matrix, axis=0).tolist()
    var_ax_2 = np.var(matrix, axis=1).tolist()
    var_flat = np.var(list)

    st_dv_ax_1 = np.std(matrix, axis=0).tolist()
    st_dv_ax_2 = np.std(matrix, axis=1).tolist()
    st_dv_flat = np.std(list)

    max_ax_1 = np.max(matrix, axis=0).tolist()
    max_ax_2 = np.max(matrix, axis=1).tolist()
    max_flat = np.max(list)

    min_ax_1 = np.min(matrix, axis=0).tolist()
    min_ax_2 = np.min(matrix, axis=1).tolist()
    min_flat = np.min(list)

    sum_ax_1 = np.sum(matrix, axis=0).tolist()
    sum_ax_2 = np.sum(matrix, axis=1).tolist()
    sum_flat = np.sum(list)

    calculations = {
        'mean': [mean_ax_1, mean_ax_2, mean_flat],
        'variance': [var_ax_1, var_ax_2, var_flat],
        'standard deviation': [st_dv_ax_1, st_dv_ax_2, st_dv_flat],
        'max': [max_ax_1, max_ax_2, max_flat],
        'min': [min_ax_1, min_ax_2, min_flat],
        'sum': [sum_ax_1, sum_ax_2, sum_flat]
    }

    return calculations

except Exception as e:
    return f"An error occurred: {str(e)}"

OUTPUT

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36

Challenge Information:

Data Analysis with Python Projects - Mean-Variance-Standard Deviation Calculator

You appear to have created this post without editing the template. Please edit your post to Tell us what’s happening in your own words.

Can you give a more detail about the error message? Link to your replit?

Maybe you need to configure run in your .replit. Show hidden files, and check your .replit file for this line:
run = "python main.py"


Screenshot 2023-10-02 073220

1 Like

https://replit.com/join/zeqofsyfgl-smrutiparida

hey you there please help it will be handy. and can you provide your gmail for further help

Happy to help. Don’t add duplicate topics, I can help here. Taking a look.

sure and thanks for help

Here is the full error:

..F
======================================================================
FAIL: test_calculate_with_few_digits (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/SmrutiParida-mean-variance-standard-deviation-calculator-3/test_module.py", line 18, in test_calculate_with_few_digits
    self.assertRaisesRegex(ValueError, "List must contain nine numbers.", mean_var_std.calculate, [2,6,2,8,4,0,1,])
AssertionError: ValueError not raised by calculate

----------------------------------------------------------------------
Ran 3 tests in 0.003s

FAILED (failures=1)

Important part is here: AssertionError: ValueError not raised by calculate

From the instructions:

If a list containing less than 9 elements is passed into the function, it should raise a ValueError exception with the message: “List must contain nine numbers.”

Instead of raising a Value Error, your function is just returning a string

1 Like

so can u guide me what to do

There is a pretty straightforward example of raising a Value Error here:

https://stackoverflow.com/questions/2052390/manually-raising-throwing-an-exception-in-python

And some good information here:
https://www.geeksforgeeks.org/python-raise-keyword/

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.