0
How do I make this work?
[1, 2, 3] + 1 = [2, 3, 4] The number list is [1, 2, 3] and when I input another integer like 1, the result would be [2, 3, 4]
3 odpowiedzi
+ 3
You could also just use a numpy array
https://code.sololearn.com/cCpZ723Q3roW/?ref=app
+ 3
qwertyuiop ,
here is a description how to do the task with a simple for loop:
create a new empty list
take a number as input from the user and convert it to integer and store it in a variable
use a for loop and iterate over the input list
take the number from the loop variable and add the value from the input to it
append the result of this addition to the new list
after loop is done, print the new list
+ 1
nums = [1, 2, 3]
r = map(lambda x: x+1, nums)
print(list(r))