Write a python program to Swap the First and the Last element of the list

Tech Programmer
0

WRITE A PYTHON PROGRAM TO SWAP THE FIRST AND THE LAST ELEMENT OF THE LIST.


CODE FOR THE ABOVE  PYTHON  PROGRAM :



list1 = []
n = int(input(" ENTER THE SIZE OF THE LIST: "))
print("\n")
for i in range(0,n):
    item = int(input(" ENTER THE VALUES OF THE LIST : "))
    list1.append(item)
print("\n")
print(" USER LIST IS : ",list1)
s = len(list1)
temp = list1[0]
list1[0]=list1[s-1]
list1[s-1]=temp
print("  NEW LIST IS : ",list1)


WRITTEN CODE FOR THE ABOVE PROGRAM :


list1 = []

n = int(input(" ENTER THE SIZE OF THE LIST: "))

print("\n")

for i in range(0,n):

    item = int(input(" ENTER THE VALUES OF THE LIST : "))

    list1.append(item)

print("\n")

print(" USER LIST IS : ",list1)

s = len(list1)

temp = list1[0]

list1[0]=list1[s-1]

list1[s-1]=temp

print("  NEW LIST IS : ",list1)


OUTPUT :



Post a Comment

0Comments
Post a Comment (0)

Featured Highlighted Categories

You'll discover all of the most up-to-date bring innovative here.

Python List theory with List Programs
Get complete python lists theory and list basic and insane programs for your practice.
CBSE SAMPLE PAPERS
Get CBSE sample and question papers of last 7 years with answers to get best practice for your Board Exams
Python String theory and String Programs
Python strings complete theory with illustrations and practice programs for free