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

Tell us what’s happening:

2 errors in testing main of mean_var_std and i have no idea why

Your code so far

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36

Challenge Information:

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

Welcome to the forum @Ka-iPy

The assertion error and diff gives you a lot of information to track down a problem. For example:

AssertionError: 'Year' != 'Years'
- Year
+ Years
?     +

Your output comes first, and the output that the test expects is second.

AssertionError: ‘Year’ != ‘Years’

Your output: Year does not equal what’s expected: Years

This is called a diff, and it shows you the differences between two files or blocks of code:

- Year
+ Years
?     +

- Dash indicates the incorrect output
+ Plus shows what it should be
? The Question mark line indicates the place of the character that’s different between the two lines. Here a + is placed under the missing s .

Here’s another example:

E       AssertionError: Expected different output when calling "arithmetic_arranger()" with ["3801 - 2", "123 + 49"]
E       assert '  3801      123    \n   - 2     + 49    \n------    -----    \n' == '  3801      123\n-    2    +  49\n------    -----'
E         -   3801      123
E         +   3801      123    
E         ?                ++++
E         - -    2    +  49
E         +    - 2     + 49    
E         - ------    -----
E         + ------    -----    
E         ?                +++++

The first line is long, and it helps to view it as 2 lines in fixed width characters, so you can compare it character by character:

'  3801      123    \n   - 2     + 49    \n------    -----    \n'
'  3801      123\n-    2    +  49\n------    -----'

Again, your output is first and the expected output is second. Here it’s easy to see extra spaces or \n characters.

E         -   3801      123
E         +   3801      123    
E         ?                ++++

Here the ? line indicates 4 extra spaces at the end of a line using four + symbols. Spaces are a little difficult to see this way, so it’s useful to use both formats together.

I hope this helps interpret your error!

Happy coding

Well,here is the code and i have no ideawhy isnt it correct even though it gives the same output

import numpy as np




def calculate(List:list):
    try:
        if len(List)==9:
            matrix = np.array(List).reshape((3,3))
            flat = matrix.flatten()


            
            calculations ={
                    'mean': [list(np.mean(matrix,axis=0)), list(np.mean(matrix,axis=0)), np.mean(flat)],
                    'variance': [list(np.var(matrix,axis=0)), list(np.var(matrix,axis=1)), np.var(flat)],
                    'standard deviation': [list(np.std(matrix, axis=0)), list(np.std(matrix, axis=1)), np.std(flat)],
                    'max': [list(np.max(matrix, axis=0)), list(np.max(matrix, axis=1)), np.max(flat)],
                    'min': [list(np.min(matrix, axis=0)),list(np.min(matrix, axis=1)),np.min(flat)],
                    'sum': [list(np.sum(matrix, axis=0)),list(np.sum(matrix, axis=1)),np.sum(flat)]

            }
            #output = ""
            #for key,value in calculations.items():

            #    output += f'\n{key}:{value}'
            
            
            #return output
            return calculations


        else:
            raise ValueError("List must contain nine numbers.")
   
    except(TypeError,AssertionError):
        print("List must contain nine numbers.")

Can you provide your output and any error messages?

Hi @Ka-iPy ,

I tried your code. Can you please check if you are correctly implementing the calculations for the second axis? There are cases where there is some disagreement with the expected answer when using the test example:
[0,1,2,3,4,5,6,7,8]