Monday, May 17, 2021

Easy level problem 1

Finding the second lowest mark:

Given the students name and marks finding the  students name who has second lowest mark.
In case of more than one student with second lowest mark, arrange the names alphabetically.
 
Input format:
total number of students  n.
following  n*2 lines of names with marks.
Output format:
names arranged alphabetically.

Input:
7
Ramya
87.9
Abi
90.5
harry
99.5
Keerthi
60.5
preethi
60.5
nikita
60.5
Lavanya
50
 
Solution:
 
n=int(input())
main_list=[]
for i in range(0,n):
    sub_list=[]
    name=input().strip()
    mark=float(input())
    sub_list.append(mark)
    sub_list.append(name)
    main_list.append(sub_list)
main_list.sort()
lowest=main_list[0]

for i in main_list:
    if lowest[0] in i:
        main_list.remove(i)
        
second_lowest_mark=main_list[0][0]
second_lowest_name=main_list[0][1]
result=[]

for i in main_list:
    if second_lowest_mark in i:
        result.append(i[1])
result.sort()
print(result)
        
 
 
 

No comments:

Post a Comment

Anaconda Installation

In this post we will discuss about Anaconda and its installation. Anaconda comes with number of applications(jupyter notebook included), dat...