CBSE Class 12 Computer Science
Question 46 of 68
Data Structures - I : Linear Lists — Question 2
Back to all questionsNumLst = [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]
NumLst = [2, 5, 1, 7, 3, 6, 8, 9]— This line creates a list calledNumLstcontaining the given numbers [2, 5, 1, 7, 3, 6, 8, 9].SqLst = []— This line initializes an empty list calledSqLst.for num in NumLst:— This line starts aforloop that iterates over each elementnumin theNumLstlist.SqLst.append(num * 2)— Inside the loop, eachnumis multiplied by 2, and the result is appended to theSqLstlist.print(SqLst)— This line prints the resulting listSqLst.