Let's quickly examine greater than, less than and equal to. Given values A and B, when A is greater than B, or A is less than B, we may conclude that A does not equal B. This means that when we compare two numbers of inequaltiy, we can dismiss equality.
if A < B: print "A less than B"
elif A > B: print "A greater than B"
else: print "A equals B"
Now consider not equal to,
!-, How does that differ from above? By being less selective.
A != B
is True for both cases, if and elif. So it demonstrates a non-identity, but it doesn't describe their differences. It only answers the question, "Does A equal B?" with 'yes' or 'no'.
This is an important distinction that definitely plays a role in many logical expressions, but it must be qualified as meeting the exact needs. We need to choose our expressions carefully and always work toward the one that best suits the objective.
Now let's look at how a computer can help us to make decisions when the data is not 'literal'. We would not ask a computer if 6 is greater than 5, literally. We already know the answer and we don't need a program to tell us. But what if 6 is the value 'hidden' in A, and 5 is hidden in B? This is a set of states that have arisen within the environment (data and interface) that the programmer couldn't have known, literally, when the program was coded. They are said to be dynamic.
Dynamic is what computers do best. Constant change is in their DNA, so to speak. In the above code example we have the computer describe the comparison of A to B. As you progress through your learning, try to think in terms of dynamic, and not literal so the mechanics of programming take hold. Variables and objects are easier to visualize once we begin to relate them to datum, data structures, data types and algorithms.
We can delve into the function in your assignment with the above notwithstanding. It suggests a dynamic nature immediately upon examining the first line...
Here we see that
answer is the dynamic entity in that we don't kinow what it represents at the time of writing the program. Our function needs to figure this out for itself. That's where the above conditional statement comes in.
We will have one literal, 5, since that is a CONSTANT in our code and remains fixed and unchanging so we can write it as the primitive value.
if answer < 5:
# we must subtract some number 'n' from 5 to go down the number line
elif answer > 5:
# we must add some number 'n' to 5 to go up the number line
# no movement required
By the above, the calling program can describe the relationship of
5 in terms of a value that is suggestive of inequality or identity, AND the direction on the number line to