List and describe three possibilities to consider if a function is not working ?
Create examples of each possibility and list the code for each example ?
Define " precondition " and " precondition " ?
Possibilities are:
When precondition is violated.
When postcondition is violated
When there is wrong usage of return value or the return value is not placed correctly.
Code example to illustrate the above possibilities
def factorial(n):
space = ' ' * (4 * n)
print space, 'factorial', n
if n == 0:
print space, 'returning 1'
return 1
else:
recurse = factorial(n-1)
result = n * recurse
print space, 'returning', result
return result
Precondition -A problem before the function’s parameters are passed into the parameters.
Comments
Leave a comment