Professional Documents
Culture Documents
The Three Possibilities To Consider If A Function Is Not Working
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:
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: