Problem Description
Python Program to Swap the First and Last Value of a List
Input:
First Line:Number of elements in list
Second Line:Elements of the List
Output:
Print the new list after swappingCODING ARENA
a=[]
n= int(input())
for x in range(0,n):
element=int(input())
a.append(element)
temp=a[0]
a[0]=a[n-1]
a[n-1]=temp
print("New list is:")
print(a)
Test Case 1
Input (stdin)4 23 45 67 89
Expected OutputNew list is: [89, 45, 67, 23]
Test Case 2
Input (stdin)3 56 34 78
Expected OutputNew list is: [78, 34, 56]
n = int(input())
ReplyDeleteli = []
for i in range(n):
x=int(input())
li.append(x)
li[0],li[-1]=li[-1],li[0]
print(li)