Professional Documents
Culture Documents
Using your notes from class discussion, your textbook and internet
define with relevant annotated examples the following: -
Error types
Syntax error
Logic error
Runtime error
Error detection techniques
Flags (to debug errors)
Debugging output statements
Stubs
For each dot point you will need to come up with a comprehensive
definitive, 2 annotated examples (explain why the example is
relevant to the explanation of this concept) from either VS Code or
from the command console of the relevant concept/technique.
Syntax Error
-make an error in the grammar of the code
______________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
Annotated examples
print ("hello")
print ("hello"
if 2 == 3:
print('hello')
else if 2 == 2:
print('goodbye')
______________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
num1 = input("please enter a number")
num1 = int(num1)
num2 = input("please enter a number")
num2 = int(num2)
num3 = input("please enter a number")
num3 = int(num3)
average = num1+num2+num3/3
print (average)
int j = 0:
int k = 25/j:
Flag (to debug errors)
- Binary condition T/F, Y/N
- Set at the start of the program and change depending on the input
______________________________________________________________________
____________________________________________________________________
____________________________________________________________________
____________________________________________________________________
____________________________________________________________________
____________________________________________________________________
____________________________________________________________________
____________________________________________________________________
____________________________________________________________________
Annotated examples
big_number_flag = False
for i in range(5):
n = int (input("Enter a number"))
if n > 2000:
big_number_flag = True
else:
big_number_flag = False
# after the loop
if big_number_flag:
print("saw at least one big number")
else:
print("didn't see any big numbers")
- After the loop is finished, all you can say about the big_number_flag is
that it is True or False, depending on ONLY the LAST value input, not
all 5 values.
Debugging output (print) statements
-System output statement -traceback errors
______________________________________________________________________
____________________________________________________________________
____________________________________________________________________
____________________________________________________________________
____________________________________________________________________
____________________________________________________________________
____________________________________________________________________
____________________________________________________________________
____________________________________________________________________
Annotated examples – age?
def hypotenuse(x, y):
print("x is %f and y is %f" % (x, y))
x_2 = x**2
print(x_2)
y_2 = y**2
print(y_2)
z_2 = x_2 + y_2
print(z_2)
z = math.sqrt(z_2)
print(z)
return z
Stubs
-To down / modular approach to program design we use stubs to “stand in the place”
of module we haven’t developed yet._(flow of the program)
______________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________