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

Practical No. 6

Uploaded by

Paras Kamble
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)
4 views4 pages

Practical No. 6

Uploaded by

Paras Kamble
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

Practical no.

Name: swapnil Manish


Paras Chandan Suryavanshi
Kamble

Roll no.: S213074


S213085

Class: SE

Div: C

Batch: C3

Problem Statement: 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 quick sort and display
top five scores.

Program Code:

def quick_sort(percentages, low, high):

"""Sorts the array of percentages in ascending order.

Args:

percentages: List of student percentages.

low: Starting index. high: Ending index.

""" if low

< high:

pi = partition(percentages, low, high)

quick_sort(percentages, low, pi - 1)

quick_sort(percentages, pi + 1, high)

def partition(percentages, low, high):

"""Partitions the array around a pivot.


Args:

percentages: List of student percentages.

low: Starting index. high: Ending index.

Returns:

Pivot index which is an int.

""" pivot =

percentages[high] i = low -

1 for j in range(low, high):

if percentages[j] <= pivot:

i += 1 percentages[i], percentages[j] = percentages[j],

percentages[i] percentages[i + 1], percentages[high] = percentages[high],

percentages[i + 1] return i + 1

def display_top_five(percentages):

"""Displays the top five scores.

Args: percentages: Sorted list of

percentages.

""" print("Top Five Scores:") for i in

range(len(percentages) - 1, len(percentages) - 6, -1):

print(percentages[i])

def main():

# Main program
num_students = int(input("Enter the number of students: "))

percentages = []

for i in range(num_students):

percentage = float(input(f"Enter student {i + 1}'s percentage: "))

percentages.append(percentage)

print("\nSorting using Quick Sort:")

quick_sort(percentages, 0, len(percentages) - 1)

print("Sorted Percentages:", percentages)

display_top_five(percentages)

if __name__ == "__main__":

main()
Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy