CBSE Class 12 Computer Science
Question 53 of 68
Data Structures - I : Linear Lists — Question 9
Back to all questionsThe above code will raise an error due to an indentation error in line 2.
The correct code is:
ages = [11, 14, 15, 17, 13, 18, 25]
print(ages)
Elig = [x for x in ages if x in range(14, 18)]
print(Elig)[11, 14, 15, 17, 13, 18, 25]
[14, 15, 17]
ages = [11, 14, 15, 17, 13, 18, 25]— This line initializes a listages.print(ages)— This line prints the listages.Elig = [x for x in ages if x in range(14, 18)]— This line uses list comprehension to create new listElig, by taking the values between 14 to 17 fromageslist.print(Elig)— This line prints the listElig.