Skip to content
Case Study-based Question · Q1

Q.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.

Tripura TbseTextbookSubjective· 5mImportance★★★★★est
50% · 15/30 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

Use a dictionary keyed by roll number whose value is the immutable tuple (name, marks-tuple, percentage); write one function per requirement and let max() with a key function pick the toppers.

The idea. Roll numbers are unique — a natural dictionary key. The hint asks for the value to be an immutable type, so we store a tuple (name, marks, percentage) where marks is itself a tuple of the subject scores: a student's recorded result should not be silently editable, and a tuple guarantees that. Splitting each requirement into its own user-defined function keeps the program modular and testable.

Program:

SUBJECTS = ("English", "Maths", "Science")

def accept_details(n):
    """Accept roll number, name and subject marks of n students."""
    records = {}
    for i in range(n):
        print("Student", i + 1)
        roll = int(input("  Roll number: "))
        name = input("  Name: ")
        marks = ()
        for sub in SUBJECTS:
            marks = marks + (float(input("  Marks in " + sub + " (out of 100): ")),)
        percentage = sum(marks) / len(SUBJECTS)
        records[roll] = (name, marks, percentage)     # value is an immutable tuple
    return records

def search_student(records, roll):
    """Search a student by roll number and display the result."""
    if roll in records:
        (name, marks, perc) = records[roll]
        print("Roll", roll, "->", name, "| Marks:", marks, "| Percentage:", round(perc, 2))
    else:
        print("No student with roll number", roll)

def display_all(records):
    """Display the result of all the students."""
    print("Roll  Name    Marks (Eng, Maths, Sci)   Percentage")
    for roll in sorted(records):
        (name, marks, perc) = records[roll]
        print(roll, " ", name, " ", marks, " ", round(perc, 2))

def find_topper(records):
    """Find the topper by percentage."""
    top_roll = max(records, key=lambda r: records[r][2])
    (name, marks, perc) = records[top_roll]
    print("Topper:", name, "(Roll", str(top_roll) + ") with", round(perc, 2), "%")

def subject_toppers(records):
    """Find the topper in each subject."""
    for idx in range(len(SUBJECTS)):
        top_roll = max(records, key=lambda r: records[r][1][idx])
        (name, marks, perc) = records[top_roll]
        print("Topper in", SUBJECTS[idx], ":", name, "with", marks[idx], "marks")

n = int(input("How many students? "))
data = accept_details(n)
display_all(data)
search_student(data, int(input("Enter roll number to search: ")))
find_topper(data)
subject_toppers(data)

Sample run (3 students):

How many students? 3
Student 1
  Roll number: 101
  Name: Aman
  Marks in English (out of 100): 78
  Marks in Maths (out of 100): 92
  Marks in Science (out of 100): 85
Student 2
  Roll number: 102
  Name: Bina
  Marks in English (out of 100): 88
  Marks in Maths (out of 100): 79
  Marks in Science (out of 100): 91
Student 3
  Roll number: 103
  Name: Chetan
  Marks in English (out of 100): 92
  Marks in Maths (out of 100): 96
  Marks in Science (out of 100): 89
Roll  Name    Marks (Eng, Maths, Sci)   Percentage
101   Aman   (78.0, 92.0, 85.0)   85.0
102   Bina   (88.0, 79.0, 91.0)   86.0
103   Chetan   (92.0, 96.0, 89.0)   92.33
Enter roll number to search: 102
Roll 102 -> Bina | Marks: (88.0, 79.0, 91.0) | Percentage: 86.0
Topper: Chetan (Roll 103) with 92.33 % …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.