107 lines
2.6 KiB
Python
107 lines
2.6 KiB
Python
|
NoOfStudents = int(input("Enter number of students: "))
|
||
|
list1 = []
|
||
|
list2 = []
|
||
|
for i in range(0,NoOfStudents):
|
||
|
n = float(input("Enter student percentage: "))
|
||
|
list2.append(n)
|
||
|
for j in list2:
|
||
|
if(j != -1):
|
||
|
list1.append(j)
|
||
|
|
||
|
def avg():
|
||
|
sum1 = 0
|
||
|
for i in list1:
|
||
|
sum1 = sum1 + i
|
||
|
avg = sum1/NoOfStudents
|
||
|
print("Sum is: ",sum1)
|
||
|
print("Average is: ",avg)
|
||
|
|
||
|
def largest():
|
||
|
largest = None
|
||
|
for i in list1:
|
||
|
if(largest==None or largest<i):
|
||
|
largest = i
|
||
|
print("The highest marks is: ",largest)
|
||
|
|
||
|
def smallest():
|
||
|
smallest = None
|
||
|
for i in list1:
|
||
|
if(smallest==None or smallest>i):
|
||
|
smallest = i
|
||
|
print("The lowest marks is: ",smallest)
|
||
|
|
||
|
def frequency():
|
||
|
temp = 0
|
||
|
for i in list1:
|
||
|
max1 = 0
|
||
|
for j in range(0,len(list1)):
|
||
|
if(i == list1[j]):
|
||
|
max1 = max1 + 1
|
||
|
else:
|
||
|
continue
|
||
|
if(max1>temp):
|
||
|
temp = max1
|
||
|
k = i
|
||
|
else:
|
||
|
continue
|
||
|
print("Marks with highest frequency is: ",k)
|
||
|
print("Frequency of the number is: ",temp)
|
||
|
|
||
|
def BubbleSort():
|
||
|
temp = 0
|
||
|
for i in range(0,len(list1)-1):
|
||
|
for j in range(0,len(list1)-1):
|
||
|
if(list1[j] > list1[j+1]):
|
||
|
temp = list1[j]
|
||
|
list1[j] = list1[j+1]
|
||
|
list1[j+1] = temp
|
||
|
else:
|
||
|
continue
|
||
|
print("Sorted list is: ",list1)
|
||
|
def top5():
|
||
|
list2 = list1[::-1]
|
||
|
for j in range(0,len(list2)):
|
||
|
print("Rank ",j+1," score is",list2[j])
|
||
|
|
||
|
def selection():
|
||
|
temp = 0
|
||
|
for i in range(0,len(list1)):
|
||
|
min1 = i
|
||
|
for j in range(i+1,len(list1)):
|
||
|
if(list1[min1]>list1[j]):
|
||
|
min1 = j
|
||
|
temp = list1[i]
|
||
|
list1[i] = list1[min1]
|
||
|
list1[min1] = temp
|
||
|
print(list1)
|
||
|
|
||
|
flag = 1
|
||
|
while flag == 1:
|
||
|
print("\nThe options are: ")
|
||
|
print("1. Total and average marks are: ")
|
||
|
print("2. Highest marks among the students: ")
|
||
|
print("3. Lowest marks among the students: ")
|
||
|
print("4. Marks with highest frequency is: ")
|
||
|
print("5. Top ",len(list1)," scores using bubble sort")
|
||
|
print("6. Top ",len(list1)," scores using selection sort")
|
||
|
print("7. Top ",len(list1)," scores are: ")
|
||
|
print("8. Exit")
|
||
|
ch = int(input("Enter choice: "))
|
||
|
if(ch == 1):
|
||
|
avg()
|
||
|
elif(ch == 2):
|
||
|
largest()
|
||
|
elif(ch == 3):
|
||
|
smallest()
|
||
|
elif(ch == 4):
|
||
|
frequency()
|
||
|
elif(ch == 5):
|
||
|
BubbleSort()
|
||
|
elif(ch == 6):
|
||
|
selection()
|
||
|
elif(ch == 7):
|
||
|
top5()
|
||
|
elif(ch == 8):
|
||
|
flag = 0
|
||
|
elif(ch>8 or ch<1):
|
||
|
print("Enter valid choice")
|