Call Girls In Bhikaji Cama Place 24/7✡️9711147426✡️ Escorts Service
Conditionals
1.
2. True or False?
Boolean values are abstract concepts used in
computations.
TRUE!
Named in honor of George Boole who invented
a system of mathematics in which the abstract
concepts of true and false can be used in
computations
3. Sometimes a program needs to ”decide” whether
or not to execute certain instructions
All previous instructions have been consecutive
(sequence structure), that is:
One
After
The
Other
in the order that they
appear.
Now we can add some variability, interactivity,
and dynamisms into our applications.
4. A conditional is what we refer to as a decision
structure. A decision is made is based upon a set of
rules. We mainly will be working with the if…then.
An If decision executes a set of instructions if a
Boolean condition is true
Instruction tests a condition
The condition controls how the
application executes
Ex.
If an event occurs then a certain
outcome will happen.
If it rains, then I will wear a rain coat.
5. Conditional arguments are Boolean expressions.
We use relational operators to form Boolean
statements.
Operator Meaning
== equal to
< less than
<= less than or equals to
> greater than
>= greater than or equal to
!= not equal to
Common Mistake: Confusing = with ==
6. Code:
Creating a decision structure:
if (expression):
statement
To execute more than one statement in a block they must be indented
equally:
if (score > 90):
grade = 'A'
print(“Good Job!n”)
print(“Not part of the conditions execution”)
Good Programming: Commenting conditional blocks
Common Mistakes: Forgetting equal indent, forgetting :, forgetting
space after if
Good Practices: Use a tab not a space (easier to line up and
troubleshoot)
Space
Indent
7.
8. Code:
Creating a button object
GPIO.setup(pin# , GPIO.IN)
Using button functions to determine if
triggered
if (GPIO.input(pin#) == False):
Command
Command
9. We can nest conditional statements to have several decisions
structures evaluated within one decision tree.
This allows an application to check multiple situations for a
single desired outcome.
With an if statement if it evaluates to true it is true the body
statements executed
However, with an else it will execute when the if statement is
false
If and else compliment each other
50/50
Two halves of the same coin
Ie. If an event occurs then a certain outcome will happen, else do
something different.
Ex.
If it rains, then I will wear a rain coat, else I don’t need a jacket
Flipping a coin. If it is heads I win, else it is tails I lose(100%
outcomes)
10. Code:
Creating a nested decision structure:
if (expression):
statement
else:
statement
Good Programming: Lining up the else with the
preceding if.
Common Mistakes: Forgetting the : after the else