Python Debugging Questions
Python Debugging Questions
1. Syntax Error
print("Hello World"
Answer: Missing closing parenthesis. Correct Code: print("Hello World")
2. Indentation Error
if 5 > 2:
print("Five is greater")
Answer: Python requires indentation inside blocks. Correct Code: if 5 > 2: print("Five is greater")
3. Name Error
print(name)
Answer: Variable 'name' not defined. Correct Code: name = "Python" print(name)
4. Type Error
age = 20
print("Age is " + age)
Answer: Cannot concatenate string and integer. Correct Code: print("Age is", age)
5. Division by Zero
num = 10 / 0
Answer: Division by zero is not allowed. Fix by checking denominator before division.
7. Missing Colon
for i in range(5)
print(i)
Answer: Colon ':' missing after loop. Correct Code: for i in range(5): print(i)
8. Index Error
list1 = [1,2,3]
print(list1[3])
Answer: Index out of range (Python starts from 0). Correct Code: print(list1[2])
9. Infinite Loop
while True:
print("Hello")
Answer: Loop never stops. Fix by adding condition: count = 0 while count < 5: print("Hello")
count += 1