How do I add a number in my element?
lets say I want to add 10 to every single element in my array
I want my input to be [1,2,3,4,5] and my output to be [11,12,13,14,15]
This is what I came up with so far
def func(z):
numbers = [1, 2, 3, 4,5]
num = 10
for i in z:
numbers.append(i + num)
i = numbers[-2:]
return i
This prints 5,20 instead of 14 and 15.
z
? You also returning from loop in first iteration... simplenumbers = [n+10 for n in numbers]
is enough