0% found this document useful (0 votes)
7 views2 pages

Debugging Python Programs with Errors

The document presents five complex Python programs, each containing 5 to 8 deliberate errors for debugging practice. The programs cover various topics such as student management, dictionary operations, linked lists, and employee salary calculations. Each program includes specific errors related to variable names, syntax, and logic that need to be identified and corrected.

Uploaded by

Balajanani .R
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)
7 views2 pages

Debugging Python Programs with Errors

The document presents five complex Python programs, each containing 5 to 8 deliberate errors for debugging practice. The programs cover various topics such as student management, dictionary operations, linked lists, and employee salary calculations. Each program includes specific errors related to variable names, syntax, and logic that need to be identified and corrected.

Uploaded by

Balajanani .R
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

You said:

Give 5 complex python program with atleast 5 to 8 errors

ChatGPT said:

Perfect! I can craft 5 Python programs that are moderately complex, each containing 5–8
deliberate errors for debugging practice. I’ll make them involve data structures, loops,
functions, and classes—good for PG-level students. I won’t correct them yet; you can debug
them yourself first.

Program 1 – Student Management


class Student:
def __init__(self, name, marks):
[Link] = name
[Link] = marks

def average(self):
total = sum([Link])
return total / len(marks) # Error 1: should be [Link]

students = [
Student("Alice", [90, 85, 92]),
Student("Bob", [78, 81, 79]),
Student("Charlie", [88, 87, 85])
]

for student in student: # Error 2: should be students


print(f"{[Link]}: {[Link]()}) # Error 3: extra bracket

Errors: reference errors, wrong variable name, syntax.

Program 2 – Dictionary Operations


data = {"apple": 5, "banana": 3, "orange": 7}

for key, value in [Link]():


if value => 5: # Error 1: invalid comparison operator
print(f"{key} is enough")
else
print(f"{key} is low") # Error 2: missing colon

data["grapes"] = "ten" # Error 3: inconsistent type


total = sum([Link]()) # Error 4: can't sum strings
print("Total fruits:", total)

Program 3 – Linked List


class Node:
def __init__(self, data):
[Link] = data
[Link] = None
class LinkedList:
def __init__(self):
[Link] = 0 # Error 1: should be None

def append(self, data):


new_node = Node(data)
if [Link] == None:
[Link] = new_node
else:
current = [Link]
while [Link] != NULL: # Error 2: NULL should be None
current = [Link]
[Link] = new_node

def display(self):
current = [Link]
while current != None:
print([Link]) # Error 3: no end line separator?
current = [Link]

ll = LinkedList()
[Link](10)
[Link](20)
[Link]()

Employee Salary Calculator


class Employee:
def __init__(self, name, salary):
[Link] = name
[Link] = salary

def yearly_salary(self):
return salary * 12 # Error 1: should be [Link]

employees = [
Employee("John", 5000),
Employee("Jane", 6000)
]

for emp in employees


print(f"{[Link]} earns {emp.yearly_salary()} yearly") # Error 2:
missing colon

You might also like