Question: Write a function isBetween(x, y, z) that returns True if y = x = z or
ID: 3619668 • Letter: Q
Question
Question: Write a function isBetween(x, y, z) that returns True if y = x = z or False otherwise.Here is the chapter that talks about the above question.
-------------------------
Boolean functions
Functions can return boolean values, which is often convenient for hiding compli-
cated tests inside functions. For example:
def isDivisible(x, y):
if x % y == 0:
return True
else:
return False
The name of this function is isDivisible. It is common to give boolean functions
names that sound like yes/no questions. isDivisible returns either True or
False to indicate whether the x is or is not divisible by y.
We can make the function more concise by taking advantage of the fact that the
condition of the if statement is itself a boolean expression. We can return it
directly, avoiding the if statement altogether:
def isDivisible(x, y):
return x % y == 0
This session shows the new function in action:
>>> isDivisible(6, 4)
False
>>> isDivisible(6, 3)
True
Boolean functions are often used in conditional statements:
if isDivisible(x, y):
print "x is divisible by y"
else:
print "x is not divisible by y"
It might be tempting to write something like:
if isDivisible(x, y) == True:5.5 More recursion 55
But the extra comparison is unnecessary.
Explanation / Answer
I am assuming that the function should determine if yRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.