CBSE Class 11 Computer Science Question 100 of 104

List Manipulation — Question 14

Back to all questions
14
Question

Question 11b

Write programs as per following specifications:

'''L is a list of numbers. Print a new list where each element is the corresponding element of list L summed with number num.'''

Solution
l1 = eval(input("Enter list of numbers: "))
num = int(input("Enter the number to sum with (num): "))

l2 = []

for i in l1:
    l2.append(i + num)

print("New list:")
print(l2)
Output
Enter list of numbers: [10, 20, 30, 40, 50]
Enter the number to sum with (num): 15
New list:
[25, 35, 45, 55, 65]
Answer