The 365 Data Science team is proud to invite you to our own community forum. A very well built system to support your queries, questions and give the chance to show your knowledge and help others in their path of becoming Data Science specialists.
Ask
Anybody can ask a question
Answer
Anybody can answer
Vote
The best answers are voted up and moderated by our team

sum(list) [where list=[1,2,3,4] not working in exercise based ipynb files, as was shown during Class

sum(list) [where list=[1,2,3,4] not working in exercise based ipynb files, as was shown during Class

0
Votes
2
Answer

 
Numbers =[1, 5, 64, 24, 5]
sum(Numbers) is producing the below result!

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-10-a8c02ab2727d> in <module>
----> 1 sum(Numbers)

NameError: name 'Numbers' is not defined
2 Answers

365 Team
0
Votes

Hi Satish!
Thanks for reaching out.
Your code is correct. I am referring to both

Numbers =[1, 5, 64, 24, 5]
sum(Numbers) 

and 

list_1=[1,2,3,4]
sum(list_1)

(for the latter, please not that ‘list’ is a keyword in Python, so it is not good to use it as a variable name as well. Adding a number, particularly for the purpose of this course, solves the problem quite well!).
What you need to do to solve the issue is execute the lines where you assign a value to the variable in question.
I.e. in your case, please execute Numbers =[1, 5, 64, 24, 5] first and only then execute sum(Numbers). Otherwise what you have is code, but please remember that without executing it, it stays like that – just code. We must always execute it for it to have an effect on our work.
Hope this helps.
Best,
Martin

0
Votes

It worked. Thanks Martin 🙂 

You are very welcome! 🙂

4 months