Answer to Question #241499 in Python for Joel

Question #241499

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 " ?


1
Expert's answer
2021-09-23T17:43:46-0400

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.

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS