41.1k views
5 votes
1|>def my_q(num, den, rec = False, neg = False):

2|>>>>if rec:
3|>>>>>if neg:
4|>>>>>>return den / -num
5|>>>>>else:
6|>>>>>>return den / num
7|>>>>else:
8|>>>>>return num / den
Q: Given above is the function definition for a function called my_q. Enter what will be returned by each of the following function calls. If an error would arise, enter "Error" (without quotes).
1. my_q(20.0, 0.0, rec = True)
2. my_q(4.0, 2.0, rec = False, neg = True)

User Jreisinger
by
7.8k points

1 Answer

2 votes

Final answer:

The my_q function returns different results based on the input parameters.

Step-by-step explanation:

The given function definition is for a function called my_q in Python. Let's go through each function call and see what will be returned:

  1. my_q(20.0, 0.0, rec = True) - This function call will return an Error because it divides by zero.
  2. my_q(4.0, 2.0, rec = False, neg = True) - This function call will return -0.5 because the neg parameter is set to True which makes the function return the negative value of the division.
User Marc Eaddy
by
8.4k points