CBSE Class 12 Computer Science
Question 45 of 68
Data Structures - I : Linear Lists — Question 1
Back to all questionsNo, the above code will not work as desired.
[2, 5, 1, 7, 3, 6, 8, 9, 2, 5, 1, 7, 3, 6, 8, 9] will be stored in SqLst after the above code is executed. The multiplication operator * with a list NumLst, duplicates the elements of the list NumLst by 2 times.
The correct code is:
NumLst = [2, 5, 1, 7, 3, 6, 8, 9]
SqLst = []
for num in NumLst:
SqLst.append(num * 2)
print(SqLst)[4, 10, 2, 14, 6, 12, 16, 18]