Page 456 - Computer Science V2.0 Class 11
P. 456
break
else:
print("Invalid choice. Please enter a number between 1 and 7.")
main()
CASE STUDY-BASED QUESTION
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)
Let’s peer review the case studies of others based on the parameters given under “DOCUMENTATION TIPS” at the end of Chapter 5 and
provide a feedback to them.
Ans. def acceptDetails(numberOfStudents):
studentDetails = {}
for _ in range(numberOfStudents):
rollNumber = input("Enter Roll Number: ")
name = input("Enter Name: ")
percentage = float(input("Enter Percentage of Marks: "))
studentDetails[rollNumber] = {'name': name, 'percentage': percentage}
return studentDetails
def searchStudent(rollNumber, studentDetails):
if rollNumber in studentDetails:
return studentDetails[rollNumber]
else:
return None
def displayAllResults(studentDetails):
print("\nResults of All Students:")
for rollNumber, details in studentDetails.items():
print(f"Roll Number: {rollNumber}, Name: {details['name']}, Percentage:
{details['percentage']}")
def findTopper(studentDetails):
if not studentDetails:
return None
# Finding the student with the highest percentage
topper = max(studentDetails, key=lambda x: studentDetails[x]['percentage'])
return studentDetails[topper]
def findSubjectToppers(studentDetails):
if not studentDetails:
return None
# Finding the subject-wise toppers
subjectToppers = {'name': None, 'percentage': 0}
442 Touchpad Computer Science (Ver. 2.0)-XI

