Answer to Question #298946 in Python for Rahul

Question #298946

A teacher has taken exam of his students. He has stored marks in a dictionary where keys are the student's name and values are student's marks. Now he wants to know the name of students obtained minimum and maximum marks from this dictionary. You need to write a python function F-m-M(X) which takes dictionary as input and returns the name of student pair having minimum and maximum marks in the class. If input dictionary is empty return "Invalid Input".

Ex: Input : { 'Amit': 21, 'Aniket':34, 'Rohit': 53 }, Output: ('Amit', 'Rohit' )

Input: { } , Output: Invalid Input


1
Expert's answer
2022-02-17T07:39:27-0500
def f_m_M(dict):
    if len(dict) != 0:
        items = dict.items()
        min_value = min(items, key=lambda stud: stud[1])
        max_value = max(items, key=lambda stud: stud[1])
        return min_value + max_value
    else:
        return "Invalid input"

my_dict = { 'Amit': 44, 'Aniket':34, 'Rohit': 53 }

print(f_m_M(my_dict))

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