0% found this document useful (0 votes)
3 views3 pages

DefectReport Simple

This report details two critical bugs in a Python script, sample.py, that cause runtime crashes. The first bug, a ZeroDivisionError, occurs when attempting to divide by zero with an empty list, while the second bug, an IndexError, arises from accessing a non-existent index in a list. Both issues have been identified, explained, and fixed in the provided code examples.

Uploaded by

joelyohannan007
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

DefectReport Simple

This report details two critical bugs in a Python script, sample.py, that cause runtime crashes. The first bug, a ZeroDivisionError, occurs when attempting to divide by zero with an empty list, while the second bug, an IndexError, arises from accessing a non-existent index in a list. Both issues have been identified, explained, and fixed in the provided code examples.

Uploaded by

joelyohannan007
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

SOFTWARE DEFECT REPORT

Python Debugging Using VS Code


April 2026 | Language: Python 3.10 | Tool: VS Code Debugger

Overview
This report covers 2 bugs found in a Python script called [Link]. Both bugs cause the program
to crash at runtime. Each bug is explained with the cause, the bad code, and the fix.

Program 1 — ZeroDivisionError
File: [Link] | Function: calculate_average() | Severity: HIGH

What went wrong?


The function divides the total by the number of items in the list. If the list is empty, it tries to divide
by zero, which causes Python to crash immediately.

Bug Details
Bug Type Runtime Error — ZeroDivisionError

Line Line 5

Buggy Code return total / len(numbers)

Problem If numbers is an empty list [], len(numbers) = 0, so dividing by 0 crashes


the program.

Fixed Code if len(numbers) == 0: return 0 return total / len(numbers)

Fix Check if the list is empty first. If yes, return 0 right away — no division
needed.

Error Shown ZeroDivisionError: division by zero

Full Fixed Code


def calculate_average(numbers):
if len(numbers) == 0: # Check for empty list first
return 0 # Return 0 safely, no division
total = sum(numbers)
return total / len(numbers)

# Test it
print(calculate_average([])) # Output: 0
print(calculate_average([10, 20, 30])) # Output: 20.0

Program 2 — IndexError
File: [Link] | Function: get_user_data() | Severity: HIGH

What went wrong?


The function tries to access index 3 of a list that only has 3 items. In Python, list indices start at 0,
so a 3-item list only goes up to index 2. Asking for index 3 crashes the program.

Bug Details
Bug Type Runtime Error — IndexError

Line Line 10

Buggy Code return users[3]

Problem List has 3 items: index 0 = 'Alice', 1 = 'Bob', 2 = 'Charlie'. Index 3 does
not exist.

Fixed Code return users[2] # Access last valid index # OR return users[-1] #
Pythonic way: always gets last item

Fix Change index 3 to index 2. Even better: use users[-1] which always
returns the last item no matter the list size.

Error Shown IndexError: list index out of range

Full Fixed Code


def get_user_data():
users = ["Alice", "Bob", "Charlie"]
# Index: 0 1 2
return users[2] # Fixed: was users[3], which doesn't exist
# OR: return users[-1] # Always gets last item

# Test it
print(get_user_data()) # Output: Charlie

Summary
Bug Error Cause Severity Status

1 ZeroDivisionError Dividing by 0 (empty HIGH Fixed ✓


list)

2 IndexError Accessing index that HIGH Fixed ✓


doesn't exist

You might also like