Menu

Building the Grades and Report Card Feature

Building the Grades and Report Card Feature

def add_grade():
    subject = input("Enter Subject: ").strip()
    marks = int(input("Enter Marks (0-100): "))

    cur.execute(
        "INSERT INTO grades (roll_no, subject, marks) VALUES (?, ?, ?)",
        (roll_no, subject, marks)
    )

add_grade() takes a subject name and marks, checks that marks fall between 0 and 100, and inserts it as a new row. Since each subject is stored as a separate row, a single student can have multiple grade entries linked to the same roll number.

def view_report_card():
    cur.execute("SELECT subject, marks FROM grades WHERE roll_no = ?", (roll_no,))
    rows = cur.fetchall()

    total = 0
    for subject, marks in rows:
        total += marks

    average = total / len(rows)

    if average >= 90:
        grade_letter = "A+"
    elif average >= 75:
        grade_letter = "A"
    elif average >= 60:
        grade_letter = "B"
    elif average >= 40:
        grade_letter = "C"
    else:
        grade_letter = "F"

view_report_card() fetches all subjects and marks for that student, adds them up to get the total, and divides by the number of subjects to get the average. The chain of if-elif conditions then converts that average into a final letter grade, from A+ down to F.


Student Management System using Python (Beginner-Friendly Project Guide)

AP

Abhishek Pati





Get in Touch For Details