Menu

Building the Attendance Tracking Feature

Building the Attendance Tracking Feature

def mark_attendance():
    cur.execute("SELECT name FROM students WHERE roll_no = ?", (roll_no,))
    row = cur.fetchone()

    status = input("Enter status (Present/Absent): ").strip().capitalize()
    today = str(date.today())

    cur.execute(
        "INSERT INTO attendance (roll_no, date, status) VALUES (?, ?, ?)",
        (roll_no, today, status)
    )

mark_attendance() first checks that the entered roll number actually belongs to a real student. It then takes the status as Present or Absent, uses date.today() to automatically grab the current date, and inserts this as a new row into the attendance table.

def view_attendance():
    cur.execute("SELECT date, status FROM attendance WHERE roll_no = ? ORDER BY date", (roll_no,))
    rows = cur.fetchall()

    present_count = 0
    for r in rows:
        if r[1] == "Present":
            present_count += 1

    percentage = (present_count / total) * 100

view_attendance() pulls every attendance record for that student, then loops through the results, counting how many times the status was "Present". Dividing that count by the total number of records gives the attendance percentage.


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

AP

Abhishek Pati





Get in Touch For Details