For the SMIS System given in Chapter 5, let us do the following: Write a program to take in the roll number, name and percentage of marks for n students of Class X. Write user defined functions to - accept details of the n students (n is the number of students) - search details of a particular student on the basis of roll number and display result - display the result of all the students - find the topper amongst them - find the subject toppers amongst them [Hint: use Dictionary, where the key can be roll number and the value is an immutable data type containing name and percentage]
SMIS System - Student Management Information System
Program to manage student records using Dictionary
Dictionary to store student data
Key: Roll Number, Value: Tuple (Name, Percentage) - immutable data type
student_dict = {}
def accept_details(n): """Accept details of n students""" for i in range(n): print(f"\nEnter details for Student {i+1}:") roll = int(input("Enter Roll Number: ")) name = input("Enter Name: ") percentage = float(input("Enter Percentage: ")) student_dict[roll] = (name, percentage) print(f"\nDetails of {n} students stored successfully!")
def search_student(roll_no): """Search details of a student by roll number and display result""" if roll_no in student_dict: name, percentage = student_dict[roll_no] print("\nStudent Found:") print(f"Roll Number: {roll_no}") print(f"Name: {name}") print(f"Percentage: {percentage}%") else: print(f"\nStudent with Roll Number {roll_no} not found!")
def display_all(): """Display result of all students""" print("\nRoll_No\tName\tPercentage") for roll in sorted(student_dict.keys()): name, percentage = student_dict[roll] print(f"{roll}\t{name}\t{percentage}%")
def find_topper(): """Find the topper amongst all students""" max_percentage = 0 topper_roll = None for roll, details in student_dict.items(): if details[1] > max_percentage: max_percentage = details[1] topper_roll = roll if topper_roll: print(f"\nTopper: {student_dict[topper_roll][0]} with {max_percentage}%")
def find_subject_toppers(): """Find subject toppers amongst students""" # Categorizing students based on percentage ranges distinction = [] first_class = [] for roll, details in student_dict.items(): if details[1] >= 75: distinction.append((roll, details[0], details[1])) elif details[1] >= 60: first_class.append((roll, details[0], details[1])) print("\nDistinction (>=75%):") for roll, name, perc in distinction: print(f"{name} ({roll}): {perc}%") print("\nFirst Class (60-74%):") for roll, name, perc in first_class: print(f"{name} ({roll}): {perc}%")
Main Program
n = int(input("Enter number of students: ")) accept_details(n) roll_search = int(input("\nEnter roll number to search: ")) search_student(roll_search) display_all() find_topper() find_subject_toppers()
Explanation
This program uses a dictionary where the key is the roll number and the value is a tuple (immutable data type) containing name and percentage. The program demonstrates: (1) accept_details() - stores n student records in the dictionary, (2) search_student() - uses dictionary key access to find a student by roll number, (3) display_all() - iterates through dictionary items to display all records, (4) find_topper() - compares percentage values to find the highest scorer, (5) find_subject_toppers() - categorizes students by percentage ranges. The hint from the textbook about using dictionary with roll number as key and tuple as value is implemented.
Solution Steps
Step 1: Create an empty dictionary to store student data with roll number as key and tuple (name, percentage) as value
Step 2: Define accept_details(n) to input and store n student records using a for loop
Step 3: Define search_student(roll_no) to check if roll number exists using 'in' operator and display details
Step 4: Define display_all() to iterate through dictionary using items() method and print all records
Step 5: Define find_topper() to compare percentages and find maximum marks
Step 6: Define find_subject_toppers() to categorize students by percentage ranges
Step 7: Write main program to call all functions sequentially