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

1.

Invalid arguments – A programmer can make the mistake of passing wrong arguments types
for instance print(“Hello, World!” + 4) gives a type error as you cannot concatenate a string with
an integer but you can repeat a string with an integer e.g. print(“Hello, World!” * 4) will output
Hello, World! Hello, World! Hello, World! Hello, World!

2. The flow execution - The code will not run if the arguments inputted in the defined function
are incorrect and do not agree with the definitions in the function. The function will not execute
properly since the precondition, which is the statement that must agree to the input value on the
function's first line, has been destroyed.

3. If the function is not correctly computed or logically incorrect when called, the function does
not execute successfully. The precondition, which is supposed to be true after the flow of line
executions is processed, cannot read the function properly. The precondition statement is
destroyed. The output value has broken code if the output result does not match the numerous
lines of code in the computed program.

Precondition - For your program to be correct this condition must be true before a function
executes.

Post conditional - This is the condition that will be true at the end of the function's return if it is
executed successfully.

Precondition example:-

def addingByNum(num):

if num >= 0:

return num+num

else:

return False

Output:-

addingByNum(0)

False

addingByNum(25)

50

addingByNum(50)
100

addingByNum(n)

Traceback (most recent call last):

File "<pyshell#6>", line 1, in <module>

addingByNum(n)

NameError: name 'n' is not defined

The precondition statement n >= 0 following the function parameter is true in the example above
because the arguments (0, 25, and 50) agree with it and return as expected. However, the
argument (-1) is false since it disagrees with the precondition statement. However, argument(n)
does not agree with the function's parameter, resulting in an error indicating it is an undefined
type error.

Post Condition Example:-

def findEven(num):

if num % 2 == 0:

return print(num , "is an even number")

else:

return False

Output:-

findEven(1)

False

findEven(2)

2 is an even number

findEven(3)

False

findEven(4)
4 is an even number

You might also like