-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelection Sort.py
More file actions
59 lines (48 loc) · 1.39 KB
/
Copy pathSelection Sort.py
File metadata and controls
59 lines (48 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
marks = []
n = int(input("Enter number of students whose marks are to be displayed: "))
print(f"Enter marks for {n} students: ")
for i in range(0, n):
ele = int(input())
marks.append(ele)
# Function for Selection Sort
def Selection_Sort(marks):
for i in range(len(marks)):
min_idx = i
for j in range(i + 1, len(marks)):
if marks[min_idx] > marks[j]:
min_idx = j
marks[i], marks[min_idx] = marks[min_idx], marks[i]
return marks
# Menu-driven program
flag = 1
while flag == 1:
print("Menu")
print('''1) Selection Sort
2) Top 5 Marks''')
no = int(input("Choose option number: "))
if no == 1:
mark = Selection_Sort(marks)
print("Sorted array using selection sort is:", mark)
v = input("Continue? (y/n): ")
if v == 'y':
flag = 1
elif v == 'n':
flag = 0
break
else:
print("INVALID OPTION")
elif no == 2:
print("Top 5 marks are:")
mark = Selection_Sort(marks)
for i in range(n - 1, n - 6, -1):
print(mark[i])
v = input("Continue? (y/n): ")
if v == 'y':
flag = 1
elif v == 'n':
flag = 0
break
else:
print("INVALID OPTION")
else:
print("Option not available")