Computer Science

Write a program to increment the elements of a list with a number.

Python

Python List Manipulation

81 Likes

Answer

lst = eval(input("Enter a list: "))
print("Existing list is:", lst)

n = int(input("Enter a number: "))

for i in range(len(lst)):
    lst[i] += n

print("List after increment:", lst)

Output

Enter a list: [1, 2, 3, 4, 5]
Existing list is: [1, 2, 3, 4, 5]
Enter a number: 10
List after increment: [11, 12, 13, 14, 15]

Answered By

36 Likes


Related Questions