binary code, binary, binary system-475664.jpg
0 0
Read Time:1 Minute, 19 Second

Given the names and grades for each student in a class of  N students, store them in a nested list and print the name(s) of any student(s) having the second lowest grade.

Note: If there are multiple students with the second lowest grade, order their names alphabetically and print each name on a new line.

def FindMinimum(records):
    if(len(records)==1):
        return records[0][1] 
    min=records[0][1]
    temp=0
    for i in range(len(records)):
            if(records[i][1]<min):
                temp=min
                min=records[i][1]
    return min
def FindMinimumnot(records,z):
    if(len(records)==1):
        return records[0][1] 
    min=records[0][1]
    temp=0
    i=0
    while(True):
        min=records[i][1]
        if(min==z):
            i+=1
        else:
            break
        
    for i in range(len(records)):
            if((records[i][1]<min) ):
               if((records[i][1]!=z)):
                    temp=min
                    min=records[i][1]
    return min
def FindList(records,z):
    names= []
    for i in range(len(records)):
        if(records[i][1]==z):
            names.append(records[i][0])
    return names

if __name__ == '__main__':
    records=[]
    for _ in range(int(input())):
        record =[]
        name = input()
        record.append(name)
        score = float(input())    
        record.append(score)
        records.append(record)
    z=FindMinimum(records)
    z2=FindMinimumnot(records,z)
    listofname=FindList(records,z2)
    if(len(listofname)==1):
        print(listofname[0])
    else:
        newlist=sorted(listofname,reverse=False)
        for i in range(len(newlist)):
            print(newlist[i])
    
    

                      
Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %

About Author

Average Rating

5 Star
0%
4 Star
0%
3 Star
0%
2 Star
0%
1 Star
0%

Leave a Reply

Your email address will not be published. Required fields are marked *