Skip to content

Latest commit

 

History

History
331 lines (215 loc) · 7.38 KB

File metadata and controls

331 lines (215 loc) · 7.38 KB

Bug Report: Student Marks Management System

1. Project Information

  • Project Name: Student Marks Management System
  • Programming Language: Python
  • Affected File: student_marks.py
  • Input File: students.txt
  • Bug Report Type: Debugging and Troubleshooting

2. Project Overview

The Student Marks Management System reads student details and marks from students.txt. It calculates each student's total marks, average marks, and grade, then displays the results.

During testing, several logical, input-handling, and file-handling problems were identified in the original program.

3. Bugs Identified

Bug 1: Incorrect Average Calculation

Original code:

average = total / 4

Problem:

Each student has five subject marks, but the total was divided by four. Therefore, the calculated average was incorrect.

Example:

Total = 436
Incorrect average = 436 / 4 = 109
Correct average = 436 / 5 = 87.2

Root Cause:

The divisor was hard-coded as 4 instead of using the actual number of marks.

Fixed code:

average = total / len(marks)

Status: Fixed and tested.


Bug 2: Last Student Record Was Skipped

Original code:

for i in range(len(students) - 1):

Problem:

The loop stopped before the last student. As a result, the final student record was not displayed.

Root Cause:

Subtracting 1 from the list length caused the loop to exclude the last index.

Fixed code:

for student in students:

Reason for Fix:

Iterating directly through the list processes every student record.

Status: Fixed and tested.


Bug 3: Incorrect Grade Boundary Conditions

Original code:

if average > 90:
    grade = "A"
elif average > 75:
    grade = "B"
elif average > 60:
    grade = "C"
else:
    grade = "F"

Problem:

Students with averages exactly equal to 90, 75, or 60 would not receive the intended grade.

Root Cause:

The program used the > operator instead of >=.

Fixed code:

if average >= 90:
    grade = "A"
elif average >= 75:
    grade = "B"
elif average >= 60:
    grade = "C"
else:
    grade = "F"

Status: Fixed.


Bug 4: Missing File Handling

Problem:

If students.txt did not exist, the program could terminate with a FileNotFoundError.

Root Cause:

The file was opened without exception handling.

Fixed code:

try:
    with open("students.txt", "r") as file:
        # Read file contents
        pass
except FileNotFoundError:
    print("Error: students.txt was not found.")

Result:

The program now displays a clear error message and continues safely.

Status: Fixed and tested.


Bug 5: Invalid Non-Numeric Marks

Problem:

A record containing a value such as abc instead of a number could cause a ValueError.

Example input:

Kiran,85,abc,78,90,95

Root Cause:

The program attempted to convert every mark to an integer without handling conversion errors.

Fixed code:

try:
    marks = [int(mark.strip()) for mark in data[1:]]
except ValueError:
    print(f"Warning: Invalid marks on line {line_number}.")
    continue

Result:

The invalid record is skipped, and valid student records are still displayed.

Status: Fixed and tested.


Bug 6: Marks Outside the Valid Range

Problem:

Marks below 0 or above 100 are invalid, but the original program did not validate the range.

Example input:

Ravi,85,105,78,90,95

Root Cause:

The program converted marks to integers but did not check whether they were within the allowed range.

Fixed code:

if any(mark < 0 or mark > 100 for mark in marks):
    print(f"Warning: Marks out of range on line {line_number}.")
    continue

Result:

The invalid record is rejected, and the program continues processing valid records.

Status: Fixed and tested.


Bug 7: Malformed Student Records

Problem:

A student record with fewer or more than five marks could cause incorrect processing.

Root Cause:

The original program did not verify the number of comma-separated fields.

Fixed code:

if len(data) != 6:
    print(f"Warning: Invalid data on line {line_number}.")
    continue

Explanation:

Each valid record must contain:

  • One student name
  • Five subject marks

Therefore, every record must contain exactly six comma-separated fields.

Status: Fixed and tested.


Bug 8: Unsafe File Handling

Problem:

The original program opened the file without explicitly managing the file resource.

Root Cause:

The file was opened using:

file = open("students.txt", "r")

Fixed code:

with open("students.txt", "r") as file:
    # Read student records
    pass

Explanation:

The with statement automatically closes the file after use, even if an error occurs.

Status: Fixed.


4. Debugging and Troubleshooting Steps

  1. Read and inspected the original Python code.
  2. Checked the average calculation manually.
  3. Compared the number of marks with the divisor.
  4. Tested the program with multiple student records.
  5. Identified that the final student was skipped.
  6. Corrected the loop condition.
  7. Reviewed the grade comparison operators.
  8. Added exception handling for missing files.
  9. Added validation for numeric marks.
  10. Added validation for marks between 0 and 100.
  11. Added validation for malformed records.
  12. Refactored the program using functions and safe file handling.
  13. Ran the corrected program using:
py student_marks.py
  1. Compared the actual output with the expected output.
  2. Removed temporary test records after testing.

5. Testing Summary

Test Case Expected Result Actual Result Status
Three valid student records All students displayed All three students displayed Passed
Average calculation Correct average using five marks Correct averages displayed Passed
Last student display Final student displayed Ananya displayed Passed
Missing input file Clear error message Missing-file warning displayed Passed
Non-numeric mark Invalid record skipped Invalid-marks warning displayed Passed
Mark greater than 100 Invalid record skipped Out-of-range warning displayed Passed
Malformed record Invalid record skipped Invalid-data warning displayed Passed
Clean input after testing No warnings Program ran without warnings Passed

6. Final Result

The corrected program successfully:

  • Calculates student averages correctly.
  • Displays every student.
  • Assigns grades using correct boundary conditions.
  • Handles missing files safely.
  • Detects invalid marks.
  • Rejects marks outside the range 0–100.
  • Rejects malformed records.
  • Uses safe file handling.
  • Provides clear warning and error messages.

7. Conclusion

All identified bugs in the original Student Marks Management System were corrected and tested. The final program is more accurate, reliable, readable, and maintainable than the original version.