Write a python program to sort a list of 10 elements using Selection Sort

Tech Programmer
1

WRITE A PYTHON PROGRAM TO PERFORM SELECTION SORT TO SORT A LIST OF 10 ELEMENTS.


CODE FOR THE ABOVE  PYTHON  PROGRAM :


L = []
print("Enter 10 Elements for a List: ")
for i in range(10):
    L.append(int(input()))

for i in range(9):
    ch = 0
    x = L[i]
    for j in range(i+110):
        if x > L[j]:
            x = L[j]
            ch = ch + 1
            index = j
    if ch != 0:
        temp = L[i]
        L[i] = x
        L[index] = temp

print("\n Sorted List is: ")
for i in range(10):
    print(L[i])


WRITTEN CODE FOR THE ABOVE PROGRAM :


L = []

print("Enter 10 Elements for a List: ")

for i in range(10):

    L.append(int(input()))


for i in range(9):

    ch = 0

    x = L[i]

    for j in range(i+1, 10):

        if x > L[j]:

            x = L[j]

            ch = ch + 1

            index = j

    if ch != 0:

        temp = L[i]

        L[i] = x

        L[index] = temp


print("\n Sorted List is: ")

for i in range(10):

    print(L[i])


OUTPUT :




Post a Comment

1Comments
Post a Comment

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