Last answered:

13 Apr 2020

Posted on:

11 Apr 2020

0

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

  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 ( 0 marked as helpful)
Instructor
Posted on:

11 Apr 2020

0
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
Posted on:

13 Apr 2020

0
It worked. Thanks Martin :) 

Submit an answer