KnowledgeBoat Logo

Computer Science

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.'''

Python

Python List Manipulation

9 Likes

Answer

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]

Answered By

5 Likes


Related Questions