Skip to content
Case Study-based Question · Q1

Q.For the SMIS system extended in Chapter 6 let us do the following:
7.1 Convert all the functionality in Chapter 5 and 6 using user defined functions.

Uttarakhand UbseTextbookSubjective· 5mImportance★★★★★est
70% · 28/40 Questions
✓ Free question

Take the monolithic SMIS menu code built in Chapters 5–6 and wrap each piece of functionality (input student data, compute percentage, assign grade, display report) in its own user-defined function, leaving the menu loop as a thin dispatcher.

The idea. Chapters 5 and 6 built the Student Management Information System as straight-line code with if ladders and loops. Chapter 7's lesson is modularity: each task becomes a named, reusable function — easier to read, test, and extend (which Question 7.2 immediately exploits by adding one more function).

A model refactoring (a worked example of the conversion — your own SMIS may have slightly different fields, the structure is what matters):

# SMIS - Student Management Information System (functions version)

def getStudentData():
    """Accept one student's details and return them as a dictionary."""
    record = {}
    record["rollno"] = int(input("Enter roll number: "))
    record["name"] = input("Enter name: ")
    record["marks"] = []
    for i in range(1, 6):
        m = float(input("Enter marks in subject " + str(i) + ": "))
        record["marks"].append(m)
    return record

def percentage(marks):
    """Return the percentage for a list of marks (each out of 100)."""
    return sum(marks) / len(marks)

def grade(per):
    """Return the grade for a percentage."""
    if per >= 90:
        return "A"
    elif per >= 75:
        return "B"
    elif per >= 60:
        return "C"
    elif per >= 40:
        return "D"
    else:
        return "E"

def displayStudent(record):
    """Display the report card for one student."""
    per = percentage(record["marks"])
    print("Roll No   :", record["rollno"])
    print("Name      :", record["name"])
    print("Marks     :", record["marks"])
    print("Percentage:", round(per, 2))
    print("Grade     :", grade(per))

def menu():
    record = None
    while True:
        print()
        print("--- SMIS MENU ---")
        print("1. Enter student data")
        print("2. Display report card")
        print("3. Exit")
        choice = int(input("Enter your choice: "))
        if choice == 1:
            record = getStudentData()
        elif choice == 2:
            if record is None:
                print("No data yet - choose option 1 first.")
            else:
                displayStudent(record)
        elif choice == 3:
            print("Goodbye!")
            break
        else:
            print("Invalid choice, please try again.")

menu()

Expected output — sample run:

--- SMIS MENU ---
1. Enter student data
2. Display report card
3. Exit
Enter your choice: 1
Enter roll number: 12
Enter name: Asha
Enter marks in subject 1: 92
Enter marks in subject 2: 85
Enter marks in subject 3: 78
Enter marks in subject 4: 88
Enter marks in subject 5: 90

--- SMIS MENU ---
1. Enter student data
2. Display report card
3. Exit
Enter your choice: 2
Roll No   : 12
Name      : Asha
Marks     : [92.0, 85.0, 78.0, 88.0, 90.0]
Percentage: 86.6
Grade     : B

--- SMIS MENU ---
1. Enter student data
2. Display report card
3. Exit
Enter your choice: 3
Goodbye!

Why this is better than the Chapter 5–6 version

  • Each function does one job (single responsibility) and can be tested alone — e.g. grade(86.6) → "B".
  • percentage()/grade() return values instead of printing, so other features (like the attendance check added next in 7.2) can reuse them.
  • The menu loop shrinks to a readable dispatcher.
✓Final answer

The SMIS functionality of Chapters 5–6 is converted into user-defined functions — getStudentData(), percentage(), grade(), displayStudent() — driven by a menu() loop; behaviour is unchanged but the program is now modular and extensible.

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.