Computer Science
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
Python List Manipulation
17 Likes
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
Answered By
10 Likes
Related Questions
Consider the following code and predict the result of the following statements.
bieber = ['om', 'nom', 'nom'] counts = [1, 2, 3] nums = counts nums.append(4)
- counts is nums
- counts is add([1, 2], [3, 4])
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)
Write a program to increment the elements of a list with a number.
Write a program that reverses a list of integers (in place).