4. Logical Operators
A third logical operator is not.
The not command basically evaluates the
opposite of the statement
It can be used to simplify possible
outcomes. Instead of listing all the options
you can list the 1 it can’t be
Ex. Rolling an even number, passwords,
etc.
if not (name) == “Jason”
This reads if the name is not Jason then…
5. Code
Using ‘not’ operator:
if not (condition)
Statement
‘not’ has the highest precedence, followed by ‘and’,
then ‘or’
If the value of an expression can be determined by
evaluating just the sub-expression on left side of a
logical operator, then the sub-expression on the right
side will not be evaluated (short circuit evaluation)
8. Validating User Input
Input validation: inspecting input data to determine
whether it is acceptable
Bad output will be produced from bad input or not
utilized at all.
“Crap in, crap out”
Can perform various tests:
Range
Reasonableness
Valid menu choice
Divide by zero