In this part we have given some practice problems for python debugging. Please try them out one by one. Solution link is at the bottom

Problem 1: Syntax Error

def greet(name)
    print("Hello, " + name)

greet("Alice")

Problem 2: Indentation Error

def print_numbers():
print("1")
print("2")
print("3")

print_numbers()

Problem 3: Logical Error

def calculate_sum(n):
    result = 0
    for i in range(n):
        result += i
    return result

print(calculate_sum(5))

Problem 4: NameError

def print_message():
    print(message)

print_message()

Problem 5: Type Error

age = input("Enter your age: ")
if age > 18:
    print("You are an adult.")
else:
    print("You are not an adult.")

Problem 6: IndexError

my_list = [1, 2, 3]
print(my_list[3])

Problem 7: ValueError

age = int(input("Enter your age: "))

Day 13 : Solution Practice Problem Python Debugging

Day 13: Debugging the Python Code

2 Responses

Leave a Reply

Your email address will not be published. Required fields are marked *