Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

The three possibilities to consider if a function is not working.

1. This is when there is an error in the argument before some code is executed
2. This is when there is an error in the function and is not producing the correct results or not
behaving as intended.
3. This is when the result leads to errors or unexpected behaviors.

Note: Precondition: This is the condition that must been fulfilled before some code are executed
Postcondition: This is type of condition that must be fulfilled after some code are
executed.

Example:

Precondition:
numbers = [5.0, 10.4, -2.7, 5.4]
total = 3
for n in numbers:
assert n > 0.0, 'This should contain positive values'
total += n

Output:

numbers = [5.0, 10.4, -2.7, 5.4]


total = 3
for n in numbers:
assert n > 0.0, 'This should contain positive values'
total += n

Postcondition:

def double_number(num):
"""
Postcondition: The return value is the input number multiplied by 2.
"""
result = num * 2
assert result == num * 2,
return result

result = double_number(5)
print(result)

Output:

File "main.py", line 6


assert result == num * 2,
^
SyntaxError: invalid syntax

You might also like