0% found this document useful (0 votes)
174 views4 pages

B45 Selection Bubble Sort

The document describes a Python program that takes student percentages as input, stores them in an array, and then sorts the array using selection sort and bubble sort. It defines functions for each sorting algorithm and prints the top five scores after sorting with bubble sort. The driver code takes user input for the number of students and their percentages, stores it in an array, and offers a menu to apply the different sorting algorithms and exit.

Uploaded by

Siddhesh Mhatre
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
174 views4 pages

B45 Selection Bubble Sort

The document describes a Python program that takes student percentages as input, stores them in an array, and then sorts the array using selection sort and bubble sort. It defines functions for each sorting algorithm and prints the top five scores after sorting with bubble sort. The driver code takes user input for the number of students and their percentages, stores it in an array, and offers a menu to apply the different sorting algorithms and exit.

Uploaded by

Siddhesh Mhatre
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

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

You might also like