Are decisions in Control Flow required to be binary, as in, only evaluated to “Yes” or “No”?
Answer
In Control Flow, every decision can only be answered as either “Yes” or “No”, so they must be binary.
Python Control Flow works by utilizing boolean expressions, which are expressions that evaluate to either True (Yes) or False (No). These expressions are used in statements such as if statements which will run their code if the expression is true, or will not run their code if the expression is false and continue checking the next decision. Control Flow ‘flows’ down through each binary decision in the path until it reaches the end.
It checks through all the statements (in order) until it’s output becomes “True”, when it reaches statement where it is true, it will do the code you assign it to do
For example
my_number = 12
if my_number > 20: <— False
print: “your number is more than 20”
elif my_number == 20: <— False
print: “your number is 20”
elif my_number < 20 <— True
print “your number is less than 20”
because that one evaluates to true, it says “your number is less than 20”
I’m not an expert in Python but fuzzy logic is not included into the basic install of Python. You will need to install it with pre-installations of
NumPy >= 1.6,
SciPy >= 0.9, and
NetworkX >= 1.9.
my_number = 12
if my_number>20:
print('your number is more than 20')
elif my_number==20:
print(f'your number is {my_number}')
else:
print('your number is less than 20')
I think that from a design perspective, having binary decisions only would force us to slice the code into simple pieces, as simple as a “yes/no” decision.