Program:
def reverseList():
global list1
#Using reverse() function to reverse the list in place
#This will not create any new list
list1.reverse()
print("Reversed List:",list1)
#Defining empty list
list1 = list()
#Getting input for number of elements to be added in the list
inp = int(input("How many elements do you want to add in the list? "))
#Taking the input from user
for i in range(inp):
a = int(input("Enter the elements: "))
list1.append(a)
#Printing the list
print("The list entered is:",list1)
#The function reverseList is called to reverse the list
reverseList()
ā
OUTPUT:
How many elements do you want to add in the list? 6
Enter the elements: 1
Enter the elements: 2
Enter the elements: 4
Enter the elements: 5
Enter the elements: 9
Enter the elements: 3
The list entered is: [1, 2, 4, 5, 9, 3]
Reversed List: [3, 9, 5, 4, 2, 1]