Code Debugging: Example Code in Python
Python code with 3 syntax errors: Debugged code (corrections in green):
print("This line of code is before both IF-ELSE functions")
print("This line of code is before both IF-ELSE functions"
countervariable = 125 countervariable = 125
if (countervarable < 100): if (countervariable < 100):
print("Counter is smaller than 100") print("Counter is smaller than 100")
print("This line is in the first if section") print("This line is in the first if section")
else else:
print("Counter is greater than 100") print("Counter is greater than 100")
print("This line is in the first else section")
print("This line is in the first else section")
number = 3
if (number > 0):
number = 3
print("Number is a positive number) if (number > 0):
print("This line is in the second if section") print("Number is a positive number")
else: print("This line is in the second if section")
print("Number is a negative number") else:
print("This line is in the second else section") print("Number is a negative number")
print("This line of code is after both of the IF-ELSE functions")
print("This line is in the second else section")
print("This line of code is after both of the IF-ELSE functions")