You are on page 1of 3

'''NAME-PRITI RAJESH JAGTAP

ROLL NO-19

Assignment 6: Write a Python program to store first year percentage


of students in array. Write function for sorting array of floating
point numbers in ascending order using
a) Selection Sort
b) Bubble sort and display top five scores'''

n=int(input("Enter no of students in fe:"))


L=[]
while True:
ch=int(input('''
1.selection sort
2.Bubble sort
3.exit
'''))
if(ch==1):

print("SELECTION SORT:")
for i in range (1,n+1):
per=float(input("percentage of student:"))
L.append(per)
size=len(L)

print("Original list is:")


print(L)
for i in range (size):
min=i
for j in range (i,n):
if(L[j]<L[min]):
min=j
# ind=j
#print(ind)
c=L[min]
L[min]=L[i]
L[i]=c
print("Sorted list is:")
print(L)

elif(ch==2):
print("BUBBLE SORT:")
for i in range (1,n+1):
per=float(input("Enter percentage of students:"))
L.append(per)
size=len(L)
print("Original list is:")
print(L)

for i in range (size):


max=size
for j in range (0,size-1):
if(L[j]>L[j+1]):
c=L[j]
L[j]=L[j+1]
L[j+1]=c
print("Sorted list is:")
print(L)

else:
break;

OUTPUT:
Enter no of students in fe:5

1.selection sort
2.Bubble sort
3.exit
1
SELECTION SORT:
percentage of student:87
percentage of student:56
percentage of student:44
percentage of student:87# #9
percentage of student:33
Original list is:
[87.0, 56.0, 44.0, 89.0, 33.0]
Sorted list is:
[33.0, 44.0, 56.0, 87.0, 89.0]

1.selection sort
2.Bubble sort
3.exit
2
BUBBLE SORT:
Enter percentage of students:88
Enter percentage of students:67
Enter percentage of students:45
Enter percentage of students:33
Enter percentage of students:23
Original list is:
[33.0, 44.0, 56.0, 87.0, 89.0, 88.0, 67.0, 45.0, 33.0, 23.0]
Sorted list is:
[33.0, 44.0, 56.0, 87.0, 88.0, 67.0, 45.0, 33.0, 23.0, 89.0]
Sorted list is:
[33.0, 44.0, 56.0, 87.0, 67.0, 45.0, 33.0, 23.0, 88.0, 89.0]
Sorted list is:
[33.0, 44.0, 56.0, 67.0, 45.0, 33.0, 23.0, 87.0, 88.0, 89.0]
Sorted list is:
[33.0, 44.0, 56.0, 45.0, 33.0, 23.0, 67.0, 87.0, 88.0, 89.0]
Sorted list is:
[33.0, 44.0, 45.0, 33.0, 23.0, 56.0, 67.0, 87.0, 88.0, 89.0]
Sorted list is:
[33.0, 44.0, 33.0, 23.0, 45.0, 56.0, 67.0, 87.0, 88.0, 89.0]
Sorted list is:
[33.0, 33.0, 23.0, 44.0, 45.0, 56.0, 67.0, 87.0, 88.0, 89.0]
Sorted list is:
[33.0, 23.0, 33.0, 44.0, 45.0, 56.0, 67.0, 87.0, 88.0, 89.0]
Sorted list is:
[23.0, 33.0, 33.0, 44.0, 45.0, 56.0, 67.0, 87.0, 88.0, 89.0]
Sorted list is:
[23.0, 33.0, 33.0, 44.0, 45.0, 56.0, 67.0, 87.0, 88.0, 89.0]

1.selection sort
2.Bubble sort
3.exit
3

You might also like