8th Jan 2020, 7:57 AM
pamino
pamino - avatar
4 Answers
+ 14
first you have to append y before returning the sum def f(x): d=[] for i in range(x): y= i+2 d.append(y) return y z= 3 w=f(z) print(sum(w))
8th Jan 2020, 8:00 AM
xrezie
xrezie - avatar
8th Jan 2020, 8:02 AM
pamino
pamino - avatar
+ 1
Avinesh thanks too
8th Jan 2020, 8:12 AM
pamino
pamino - avatar
0
Your last line should be just- print(w) I guess and even that wouldn't make much sense if you are trying to return the sum of all numbers being updated inside the method. print(w) will just return the last updated y which would be the last in range number 2 and +2 added to it which is 4. I just played with the code and I think probably this is what you are looking for- def f(x): d=[] for i in range(x): y= i+2 d.append(y) return d z= 3 w=f(z) print(sum(w))
8th Jan 2020, 8:05 AM
Avinesh
Avinesh - avatar