+ 3
i have a problem with 2 codes
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))
+ 1
tasty candie thanks help with this too
https://www.sololearn.com/discuss/2127246/?ref=app
+ 1
Avinesh thanks too
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))