NAME:-DHANANJAY MOTILAL NERKAR
DIV:-B45
Write a Python program to store first year percentage of students in array. Write a function for
sorting array of floating point numbers in ascending order using
a) Selection Sort
b) Bubble Sort and display top five scores
"""
Write a Python program to store first year percentage of students in
array. Write a function for sorting array of floating point numbers in
ascending order using
a) Selection Sort
b) Bubble Sort and display top five scores
"""
def SelectionSort(arr,n):
for i in range(n):
Min = i
for j in range(i+1,n):
if(arr[j]<arr[Min]):
Min = j
temp=arr[i]
arr[i]=arr[Min]
arr[Min]=temp
print(arr)
def BubbleSort(arr,n):
i = 0
for i in range(n-1):
for j in range(0,n-i-1):
if(arr[j] > arr[j+1]):
temp = arr[j]
arr[j] = arr[j+1]
arr[j+1] = temp
print(arr)
print("Top Five Scores are...")
for i in range (len(arr)-1,1,-1):
print(arr[i])
#Driver Code
print("\nHow many students are there?")
n = int(input())
array = []
i=0
for i in range(n):
print("\n Enter percentage marks")
item = float(input())
array.append(item)
print("You have entered following scores...\n")
print(array)
while(True):
print("Main Menu")
print("\n 1. Selection Sort")
print("\n 2. Bubble Sort")
print("\n 3. Exit")
print("\n Enter your Choice: ")
choice = int(input())
if(choice == 1):
print("\n The sorted Scores are...")
SelectionSort(array,n)
elif(choice ==2):
print("\n The sorted Scores are...")
BubbleSort(array,n)
else:
print("Exit")
break
OUTPUT :-
How many students are there?
10
Enter percentage marks
35
Enter percentage marks
28
Enter percentage marks
79
Enter percentage marks
98
Enter percentage marks
46
Enter percentage marks
38
Enter percentage marks
67
Enter percentage marks
84
Enter percentage marks
37
Enter percentage marks
84
You have entered following scores...
[35.0, 28.0, 79.0, 98.0, 46.0, 38.0, 67.0, 84.0, 37.0, 84.0]
Main Menu
1. Selection Sort
2. Bubble Sort
3. Exit
Enter your Choice:
1
The sorted Scores are...
[28.0, 35.0, 37.0, 38.0, 46.0, 67.0, 79.0, 84.0, 84.0, 98.0]
Main Menu
1. Selection Sort
2. Bubble Sort
3. Exit
Enter your Choice:
2
The sorted Scores are...
[28.0, 35.0, 37.0, 38.0, 46.0, 67.0, 79.0, 84.0, 84.0, 98.0]
Top Five Scores are...
98.0
84.0
84.0
79.0
67.0
46.0
38.0
37.0
Main Menu
1. Selection Sort
2. Bubble Sort
3. Exit
Enter your Choice:
3
Exit