Write a python program for swapping the first and last element of the list using function
Coding:
def swap(x):
x[0],x[-1]=x[-1],x[0]
return(x)
list=[]
r=int(input("Enter the range of list : "))
for i in range(r):
n=int(input("Enter the number : "))
list.append(n)
print("List Before Swapping : ",list)
r=swap(list)
print("List After Swapping : ",r)
return(x)
list=[]
r=int(input("Enter the range of list : "))
for i in range(r):
n=int(input("Enter the number : "))
list.append(n)
print("List Before Swapping : ",list)
r=swap(list)
print("List After Swapping : ",r)
Output:
Enter the range of list : 5
Enter the number : 23
Enter the number : 90
Enter the number : 34
Enter the number : 51
Enter the number : 67
List Before Swapping : [23, 90, 34, 51, 67]
List After Swapping : [67, 90, 34, 51, 23]