What is the definition of precondition and post condition statement
# A precondition is a condition that must be met at the beginning of a function
#or program in order for it to work correctly.
# Postconditions are those conditions that guarantee that a function or program
# will return the correct result.
# For example, take the function of calculating the real roots of the equation
def get_square_root(a, b, c):
assert all([type(i) is int or type(i) is float for i in (a,b,c)]),"Input Error"
assert b**2-4*a*c>=0,"Calculation Error"
return (-b+(b**2-4*a*c)**.5)/(2*a), (-b-(b**2-4*a*c)**.5)/(2*a)
# In this case
# assert all([type(i) is int or type(i) is float for i in (a,b,c)]),"Input Error"
# these are preconditions the correct operation of the function is possible
# only with numeric arguments
# assert b**2-4*a*c>=0,"Calculation Error"
# this postcondition guarantees the derivation of only
# real roots of the equation
Comments
Leave a comment