Page 235 - Information_Practice_Fliipbook_Class11
P. 235
Case Study Based Question
For the SMIS System given in Chapter 3, let us do the following:
1. Write a program to take in the roll number, name and percentage of marks for n students of Class X and do the following:
• 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 an immutable data type containing name and percentage.)
Ans. # Initialize an empty dictionary to store student details
studentsDict = {}
# Accept details of n students
n = int(input("Enter the number of students: "))
for _ in range(n):
rollNumber = input("Enter Roll Number: ")
name = input("Enter Name: ")
percentage = float(input("Enter Percentage of Marks: "))
# Store details in the dictionary using roll number as the key
studentsDict[rollNumber] = {'Name': name, 'Percentage': percentage}
while True:
# Display menu
print("\nMenu:")
print("1. Enter Student Details")
print("2. Search Student Details by Roll Number")
print("3. Display All Student Details")
print("4. Find Topper")
print("5. Find Subject Toppers")
print("6. Exit")
choice = int(input("Enter your choice (1-6): "))
if choice == 1:
# Accept details of a new student
rollNumber = input("Enter Roll Number: ")
name = input("Enter Name: ")
percentage = float(input("Enter Percentage of Marks: "))
studentsDict[rollNumber] = {'Name': name, 'Percentage': percentage}
print("Details added successfully.")
elif choice == 2:
# Search and display details of a particular student by roll number
rollNumber = input("Enter Roll Number to search: ")
if rollNumber in studentsDict:
print(f"Details for Roll Number {rollNumber}:")
print(f"Name: {studentsDict[rollNumber]['Name']}")
print(f"Percentage: {studentsDict[rollNumber]['Percentage']}")
else:
Python Dictionaries 221

