CBSE Class 11 Computer Science
Question 85 of 104
List Manipulation — Question 21
Back to all questions 21
Question Question 19
What is the output of the following code?
numbers = list(range(0, 51, 4))
results = []
for number in numbers:
if not number % 3:
results.append(number)
print(results)Answer
Output
[0, 12, 24, 36, 48]
Explanation
list(range(0, 51, 4)) will create a list from 0 to 48 with a step of 4 so numbers will be [0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48]. For loop will traverse the list one number at a time. if not number % 3 means if number % 3 is equal to 0 i.e. number is divisible by 3. The numbers divisible by 3 are added to the results list and after the loop results list is printed.