Class - 12 CBSE Computer Science Important Output Questions 2025
Predict the output :
ages = [11, 14, 15, 17, 13, 18, 25]
print(ages)
Elig = [x for x in ages if x in range(14, 18)]
print(Elig)
Python
Linear Lists
4 Likes
Answer
The above code will raise an error due to an indentation error in line 2.
Working
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.
Answered By
1 Like