Dark Dubai Call Girls O525547819 Skin Call Girls Dubai
Decision Structures
1.
2. A conditional is what we refer to as a decision
structure. Where a decision is made is based upon a
set of rules. We mainly will be working with the
if…then.
Ie. If an event occurs then a certain outcome will
happen.
Ex. If it rains, then I will wear a rain coat.
3. Conditional arguments are Boolean expressions.
Question: Meaning???
We use relational operators to form Boolean expressions.
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 ==
4. 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”)
Good Programming: Commenting conditional blocks
Common Mistakes: Forgetting equal indent, forgetting :,
and forgetting space after if
Space
Indent
5.
6. We can nest conditional statements to have
several decision structures within one statement.
This allows an application to check multiple
situations for 1 desired outcome
Allows us to simplify code by not having as
many separate if statements.
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 not heads it must be tails(100% outcomes)
7. Creating a nested conditional:
if (condition):
statement
else:
statement
Good Programming: We usually line up else with
the preceding if to make it easier to find errors.
Question: Be careful testing real numbers for
equality, why?
8.
9. We can nest conditional statements to have
several decision structures within one
statement in order to test various situations for
a desired result.
Ie. If an event occurs then a certain outcome will
happen Or else if this happens do this or else do
something else
We can nest as many ElseIf’s together but each set
of conditionals can have only one Else statement
otherwise it will create a logical error
Ex.
If it rains, then I will wear a rain coat else if it snows then I
will wear gloves or else I won’t need a jacket.
Rolling a die 1,2,3,4,5,6 if lands on 1 don’t need to check
other sides b/c 100% of outcomes
10. Creating a nested conditional:
if (condition):
Statement
elif (condition):
Statement
elif (condition):
Statement
Statement
else:
Statement
Common Errors: Not Lining up Else with its preceding If.
Question: Why is a trailing else good programming?