def decide_in_the_right_way(a, b, c):
"""
return True if one of the conditions holds true
using innner functions which express the conditions in
in an easily understandable form
"""
def decision1(a, b, c):
return a < 12 and b*c > 80
def decision2(a, b, c):
return 12 and b*c/a > 20
def decision3(a, b, c):
def sensibly_named_condition(b, c):
return 10 <= b*c <= 15
return a < 0 or sensibly_named_condition(b,c)
# ... and a bunch of other similar boolean functions..
# collect the decision functions in a list
decisions = [decision_fv for name, decision_fv in locals().items()
if name.startswith("decision")]
# note the use of "for ... else"!
for decision in decisions:
result = decision(a, b, c)
if result: break
else:
result = False # executed only if no "break" occurred in the loop
return result # note that the function has a single exit point

def decide_in_the_right_way(a, b, c):
"""
return True if one of the conditions holds true
using innner functions which express the conditions in
in an easily understandable form
"""
def decision1(a, b, c):
return a < 12 and b*c > 80
def decision2(a, b, c):
return 12 and b*c/a > 20
def decision3(a, b, c):
def sensibly_named_condition(b, c):
return 10 <= b*c <= 15
return a < 0 or sensibly_named_condition(b,c)
# ... and a bunch of other similar boolean functions..
# collect the decision functions in a list
decisions = [decision_fv for name, decision_fv in locals().items()
if name.startswith("decision")]
# note the use of "for ... else"!
for decision in decisions:
result = decision(a, b, c)
if result: break
else:
result = False # executed only if no "break" occurred in the loop
return result # note that the function has a single exit point