CBSE Class 11 Computer Science Question 86 of 104

List Manipulation — Question 22

Back to all questions
22
Question

Question 20

Following code prints the given list in ascending order. Modify the code so that the elements are printed in the reverse order of the result produced by the given code.

numbers = list(range(0, 51, 4))
i = 0
while i < len(numbers):
    print(numbers[i] , end = " ")
    i += 3
# gives output as : 0 12 24 36 48

Answer

numbers = list(range(0, 51, 4))
i = len(numbers) - 1
while i >= 0:
    print(numbers[i] , end = " ")
    i -= 3
Output
48 36 24 12 0
Answer