skip to Main Content

I’m trying to solve this problem but i keep getting ~no response on stdout~ even though it functions properly with the correct output in visual studio code. The problem specifically asks us to print, and all of the solutions in the comments use the print function for output.

Here is my code :

if __name__ == '__main__':
    students = []
    for _ in range(int(input())):
        name = input()
        score = float(input())
        students.append([name,score])
    students.sort(key = operator.itemgetter(1))
    minstd = students[0][1]
    for student in students:
        if student[1] == minstd:
            students.remove(student)

    finallist = []      
    for student in students:
        if student[1] == students[0][1]:
            finallist.append(student[0])
    finallist.sort(key = operator.itemgetter(0))
    print(*finallist, sep = 'n')

Thanks in advance.

The issue : as pointed down in a response : the issue was that hackerrank needs you to import operator where as vscode doesn’t

2

Answers


  1. I can’t see the definition of ‘students’ identifier in your code

    Login or Signup to reply.
  2. if you just wanna pass the hackerrank
    just type this code, i got from discussions, because you didnt set variabel students and operator

    nested_list = []
    scores = []
    names = []
    if __name__ == '__main__':
    for _ in range(int(input())):
    name = input()
    score = float(input())
    nested_list.append([name, score])
    scores.append(score)
    scores = list(set(scores))
    scores.sort()
    names = [nested_list[m][0] for m in range(0, len(nested_list)) if nested_list[m][1] == scores[1]]
    names.sort()
    for name in names:
    print(name)`
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search