Answer to Question #242512 in Python for prosper2000

Question #242512
Section 6.9 of your textbook ("Debugging") lists three possibilities to consider if a function is not working.

Describe each possibility in your own words.

Define "precondition" and "postcondition" as part of your description.

Create your own example of each possibility in Python code. List the code for each example, along with sample output from trying to run it.
1
Expert's answer
2021-09-26T18:50:05-0400

When you debug a code, it means you locate and correct the error(s) in the code. The three possibilities of a function not working properly are:

  • Invalid arguments
  • Incorrect function operation
  • Incorrect return value or return type

Invalid arguments

This arises when the number of parameters does not match with the number of arguments passed to the function.

This is also referred to as violation of precondition

An example in python is as follows:

def add_two_num(a,b):

  return a + b

add_two_num(5)

The above function receives 1 parameter, instead of 2


Incorrect function operation

This arises when the function does not perform the required operation.

This is also referred to as violation of post-condition

An example in python is as follows:

def square_num(a):

  return a * 2

The above function returns twice a number, instead of its square.

Incorrect return value or return type

This arises when the function returns a different value or data type, different from what it is expected to return

An example in python is as follows:

def square_num(a):

   sq = a**2

  return sq

The above function is expected to return the square of a number, but it returns the number itself.


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