Sort by

recency

|

4627 Discussions

|

  • + 0 comments

    ` if name == 'main': lst_name = []

    lst_score = []
    
    for _ in range(int(input())):
        name = input()
        score = float(input())
    
        lst_name.append(name)
    
        lst_score.append(score)
    
    res = []
    
    num = sorted(list(set(lst_score)))[1]  #get 2nd ranked score (set eliminates dublicates)
    
    for i in range(len(lst_score)):
        if lst_score[i] == num:
            res.append(lst_name[i])    # append name to result if score is matched
    
    res = sorted(res)
    
    for i in res:
        print(i)
    
    ```
    
  • + 0 comments

    if name == 'main':

    n = int(input())
    che = n
    records = []
    grades = []
    maingrades = []
    names = []
    
    while(n != 0):
        name = input()
        score = float(input())
        records.append([name,score])
        n -=1
    
    for i in range(len(records)):
    
        for j in records[i]:
            if (isinstance(j,float) == True) :
                grades.append(j)
    
    grades.sort()
    lowest = grades[0]
    for i in range(len(grades)):
    
        if (grades[i] != lowest):
            maingrades.append(grades[i])
    
    for i in range(len(records)):
    
        if (maingrades[0] in records[i]):
    
            for j in records[i]:
                if(isinstance(j,str) == True):
                    names.append(j)
    
    names.sort()
    for i in names:    
        print(i)
    
  • + 0 comments

    not the best code but works,

    def lowest_in_list(list_name: list) -> int:
        low_item=list_name[0][1]
        for name, score in list_name:
            if score < low_item:
                low_item = score
        return(low_item)
    
    if __name__ == '__main__':
        students = []
        for _ in range(int(input())):
            name = input()
            score = float(input())
            students.append([name,score])
    
        #students = [['Harry', 37.21], ['Berry', 37.21], ['Tina', 37.2], ['Akriti', 41], ['Harsh', 39]]
        lowest_marks=lowest_in_list(students)
    
        # new list to find the second lowest item
        second_list = []
        for name, score in students:
            if score != lowest_marks:
                second_list.append([name,score])
        second_lowest = lowest_in_list(second_list)
    
        names=[]
        for name, score in students:
            if score == second_lowest:
                names.append(name)
    
        for name in sorted(names):
            print(name)
    
  • + 0 comments

    why isn't this working?

    if name == 'main': records=[] for _ in range(int(input())): name = input() score = float(input()) records.append([name, score])

    s=set()
    for i in range(len(records)):
        s.add(records[i][1])
    
    sc=list(s)
    
    sl=sc[len(sc)-2]
    
    n=[]
    
    for i in range(len(records)):
        if records[i][1]==sl:
            n.append(records[i][0])
    
    n.sort()
    for i in range(len(n)):
        print(n[i])
    
  • + 1 comment

    Read the number of students

    n = int(input())

    Initialize an empty list to store students' name and grade pairs

    students = []

    Read the student data

    for _ in range(n): name = input() grade = float(input()) students.append([name, grade])

    Extract all the unique grades, sort them, and get the second lowest grade

    grades = sorted(set([student[1] for student in students]))

    Find the second lowest grade

    second_lowest_grade = grades[1]

    Find the names of students with the second lowest grade

    second_lowest_students = [student[0] for student in students if student[1] == second_lowest_grade]

    Sort the names alphabetically

    second_lowest_students.sort()

    Print the names

    for student in second_lowest_students: print(student)