Are decisions in Control Flow required to be binary, as in "Yes" or "No"?


#1

Question

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.


#2

Python will cast values when they don’t quite fit the situation. “Yes” becomes True by virtue of not being the empty string.


#3

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”


#4

If x is not greater than 20 and x is not equal to 20, then x must be less than 20.

else:
    print “your number is less than 20”