Write a python program to find the name of  the students scoring minimum and maximum  marks. The student’s names and marks obtained  are stored as key value pair in a dictionary  named marksobt. Print name along with marks obtained. 


Answer:

# Assume that marksobt is a dictionary containing names as keys and marks as values

# For example, marksobt = {'Alice': 85, 'Bob': 76, 'Charlie': 92, 'David': 65, 'Eve': 74}

# Initialize two variables to store the name and marks of the minimum and maximum scorers

min_name = None

min_marks = None

max_name = None

max_marks = None

# Loop through the key-value pairs in marksobt

for name, marks in marksobt.items():

    # If min_name or min_marks is None, or if the current marks are less than the minimum marks, update the minimum name and marks

    if min_name is None or min_marks is None or marks < min_marks:

        min_name = name

        min_marks = marks

    

    # If max_name or max_marks is None, or if the current marks are more than the maximum marks, update the maximum name and marks

    if max_name is None or max_marks is None or marks > max_marks:

        max_name = name

        max_marks = marks

# Print the name and marks of the minimum and maximum scorers

print(f"The student with the minimum marks is {min_name} with {min_marks} marks.")

print(f"The student with the maximum marks is {max_name} with {max_marks} marks.")

Go Ad-free
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science, Social Science, Physics, Chemistry, Computer Science at Teachoo.