Computer Science, asked by kaustubhrathore16, 6 months ago

WAP in Python to display the series of
numbers from 50 to 30 in reverse order.

Answers

Answered by ameen8086
0

Answer:

Every list in Python has a built-in reverse() method, you can call this method to reverse the contents of the list object in-place. Reversing a list in-place means it won’t create and copy the existing elements to a new list. Instead, it directly modifies the original list object.

Explanation:

Reversing a list with list.reverse() methodUsing the Slicing Trick to Reverse a Python ListCreating Reverse Iterator with the reversed() Built-In Function

Example 1:

number_list = [10, 20, 30, 40, 50] reversed_list = number_list.reverse() print(reversed_list) number_list = [10, 20, 30, 40, 50] reversed_list = number_list.reverse() print(reversed_list)

Output:

None

Example 2:

string_list = [“One”, “Two”, “Three”, “Four”, “Five”] reversed_list = string_list.reverse() print(reversed_list)

Output:

None

Example 3:

def reverse_list(list): print(‘Old list:’, list) list.reverse() print(‘New list:’, list) number_list = [10, 20, 30, 40, 50] string_list = [“One”, “Two”, “Three”, “Four”, “Five”] reverse_list(number_list) reverse_list(string_list)

Output:

Old list: [10, 20, 30, 40, 50]

New list: [50, 40, 30, 20, 10]

Old list: [‘One’, ‘Two’, ‘Three’, ‘Four’, ‘Five’]

New list: [‘Five’, ‘Four’, ‘Three’, ‘Two’, ‘One’]

Answered by gaganadithyareddy9
0

Answer:

Hey this is in python...

nums = []

for i in range(30, 51):

   nums.append(i)

nums = nums[::-1]

for i in nums:

   print(i)

# Hope this helps!!

Similar questions