CBSE Class 12 Computer Science Question 60 of 68

Data Structures - I : Linear Lists — Question 16

Back to all questions
16
Question

Question 15(i)

Find the error. Consider the following code and predict the error(s):

y for y in range(100) if y % 2 == 0 and if y % 5 == 0
Answer
  1. The list comprehensions should be enclosed in square brackets.
  2. The code contains a syntax error as it is using two if statements within the list comprehension. We should use a single if statement with both conditions combined using the and operator.