Savitribai Phule Pune University
Second Year of Computer Engineering (2019 Course)

210247:
Data Structures Laboratory

 

Data Structures Laboratory: Write a pythonprogram to store first year percentage of students in array. Write function for sorting array of floating point numbers in ascending order using


Problem Statement:

Write a pythonprogram 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


Code:

def display(First_Year_Percentage):
    print("Top Five Marks are-")
    for i in range(-5,0):
        print(First_Year_Percentage[i])

def selection_sort(First_Year_Percentage):
    for i in range(0, len(First_Year_Percentage)):
        for j in range(i+1,len(First_Year_Percentage)):
            if(First_Year_Percentage[i]>First_Year_Percentage[j]):
                temp=First_Year_Percentage[i]
                First_Year_Percentage[i]=First_Year_Percentage[j]
                First_Year_Percentage[j]=temp
    print("Selection Sort in Done!!")
    display(First_Year_Percentage)

def bubble_sort(First_Year_Percentage):
    count=1
    while(count<len(First_Year_Percentage)):
        for i in range(0,len(First_Year_Percentage)-count):
            if(First_Year_Percentage[i]>First_Year_Percentage[i+1]):
                temp=First_Year_Percentage[i]
                First_Year_Percentage[i]=First_Year_Percentage[i+1]
                First_Year_Percentage[i+1]=temp
        count=count+1
    print("Bubble Sort in Done!!")
    display(First_Year_Percentage)

# Mian Program
if __name__=="__main__":
    First_Year_Percentage=[]
    n=int(input("Enter the Number of Students: "))
    for i in range(0,n):
        percentage=float(input("Enter the Percentage of Roll No. {}: ".format(i+1)))
        First_Year_Percentage.append(percentage)
    
    while(True):
        print("\n-----------------------Menu-----------------------\n1)Perform Selection Sort\n2)Perform Bubble Sort\n3)Exit")
        choice=int(input("Enter your choice (From 1 to 3): "))
        if(choice==1):
            selection_sort(First_Year_Percentage)
        elif(choice==2):
            bubble_sort(First_Year_Percentage)
        elif(choice==3):
            print("Thank You For Using This Program!!")
            break
        else:
            print("Please Enter the Valid Choice!!")