Tell us what’s happening:
why do I have as result "NameError: Name “calculations” is not defined ?
Your code so far
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Challenge Information:
Data Analysis with Python Projects - Mean-Variance-Standard Deviation Calculator
Welcome to the forum
Other than the obvious, would need to see your code to answer this.
Thanks! Nice to get in touch with the community. Please would you get me a feedback for my request?
ILM
March 18, 2025, 12:11pm
4
it’s impossible to know what’s going on without seeing your code
Please how can I share it with you ?
Copy/Paste your code in a comment here.
When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>
) to add backticks around text.
See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').
Thank you very much pkdvalis.
Import Numpy as Numpy
def=calculate(list)
list = ([1,2,,3,4,5,6,7,8,9])
If len(list) != 9:
raise valueError ("list must contain nine numbers")
matrix = np.array(list).reshape(3,3)
calculations = {
'mean': [matrix.mean(axis=0).tolist() , matrix.mean(axis=1).tolist() , matrix.mean()]
'variance': [matrix.var(axis=0).tolist() , matrix.var(axis=1).tolist() , matrix.var()]
'standard deviation': [matrix.std(axis=0).tolist() , matrix.std(axis=1).tolist() , matrix.std()]
'Maximum': [matrix.max(axis=0).tolist() , matrix.max(axis=1).tolist() , matrix.max()]
'Minimum': [matrix.min(axis=0).tolist() , matrix.min(axis=1).tolist() , matrix.min()]
'Sum': [matrix.sum(axis=0).tolist() , matrix.sum(axis=1).tolist() , matrix.sum()]
}
return calculations
By executing that code on the Editor, (python3 main.py) the result is : “NameError: name ‘calculations’ is not defined”
I have change the identation many time, but I still have the same result.
I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>
) to add backticks around text.
See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').
Is that the only error you get?
When I copy and paste your code I get this error:
Import Numpy as Numpy
^
SyntaxError: invalid syntax
Although there are many small errors in this code.
Are you running this in Gitpod? Can you show a screenshot running the code and the error?
The indentation is quite wrong, unless it got removed when you pasted the code.
Did you do the rest of the basic Python course already? You might need to review the basics.
Ok Sir, just a minute please …
Thanks.
Do you want to learn how to code Python? You can start here:
https://www.freecodecamp.org/learn/scientific-computing-with-python/
You need to learn how to do basics first like creating if
statements and how to define a function before you tackle this.
Can you explain how you came to write this code?
Thanks for your help. I am going through in other to improve my skills.
1 Like
Thank you very much for that great help! Your are very kind.
1 Like