Answer to Question #314060 in Python for Manish

Question #314060

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


1
Expert's answer
2022-03-19T08:52:24-0400
n = int(input())

min_score = 99999
max_score = -1

for i in range(n):
    line = input()
    name = line.split()[0]
    score = int(line.split()[1])

    if min_score > score:
        min_score = score
        min_name = name
    elif min_score == score:
        if min_name > name:
            min_name = name
    
    if max_score < score:
        max_score = score
        max_name = name
    elif max_score == score:
        if max_name > name:
            max_name = name

print(min_name, max_name)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS