Lowest and Highest score
The teacher gave out the scores of the science quiz conducted last week and asked the ones with the lowest and highest scores to group up. Print the names of the students with minimum and maximum scores, respectively.
Note: In case of a tie, choose the name which comes first in the (dictionary order).
Sample Input1
2
shakti 24
disha 26
Sample Output1
shakti disha
Sample Input2
3
ajay 23
bijay 24
sanjay 23
Sample Output2
ajay bijay
stud_num = int(input('Input:\n'))
stud_names = {}
for i in range(stud_num):
raw = input()
if len(raw.split()) == 2:
n, s = raw.split()
if isinstance(int(s), int):
stud_names[n] = int(s)
else:
raise ValueError('Score is not a number')
else:
raise ValueError('Enter just name and score')
print('Output:')
min_key = min(stud_names, key=stud_names.get)
max_key = max(stud_names, key=stud_names.get)
print(min_key, max_key)
Comments
Leave a comment