PYTHON
Lesson controls with
7 conditional
statement
Conditional statement
Refer to programming constructs that allow a
program to make decisions based on certain
conditions.
These statements enable the program to execute
different blocks of code depending on whether
certain conditions are true or false.
relational operators
Relational operators are symbols used to establish
relationships between numerical values or
expressions in programming.
These operators compare two numerical values
and determine the relationship between them,
resulting in a boolean value (true or false)
indicating whether the relationship holds true.
common relational operators
Equal to (==): Compares whether two numerical
values are equal.
Not equal to (!=): Compares whether two numerical
values are not equal.
Greater than (>): Checks if the left numerical value
is greater than the right numerical value.
common relational operators
Less than (<): Checks if the left numerical value is
less than the right numerical value.
Greater than or equal to (>=): Checks if the left
numerical value is greater than or equal to the
right numerical value.
Less than or equal to (<=): Checks if the left
numerical value is less than or equal to the right
numerical value.
logical operators
Logical operators are symbols or keywords used
to perform logical operations on one or more
boolean values or expressions, including
numerical values, in programming.
These operators combine multiple conditions or
negate them, resulting in a single boolean value
(true or false).
common logical operators
AND (and): Returns true if both operands are true.
OR (or): Returns true if at least one of the
operands is true.
NOT (not): Returns the opposite boolean value of
the operand
Note: Logical operators can also be applied to
numerical values when evaluating conditions
involving numeric expressions or comparisons.
The Most Common Conditional Statements
if statement: The if statement evaluates a
condition and executes a block of code if the
condition is true. It can be followed by an optional
else block to execute if the condition is false.
if statement
Let’s code an if statement
First, we will create an if-else function like this
if statement
Then, we will create checkboxes and buttons to
execute the if statement
if statement
Then we will create a label to show what statement
is being used
if statement
•Here is an example of the code
if statement
When this code is executed, it produce this result
The Most Common Conditional Statements
else-if statement (elif): The elif statement allows
for the evaluation of multiple conditions in
sequence. If the preceding if or elif conditions are
false, it checks the condition associated with it.
else-if statement
Let’s code an else-if(elif)
First, we will create an else-if(elif) function like this
else-if statement
Then, we will create checkboxes and buttons to
execute the else-if(elif) statement
else-if statement
Then we will create a label to show what statement
is being used
else-if statement
•Here is an example of the code
else-if statement
When this code is executed, it produce this result
The Most Common Conditional Statements
switch statement (in some languages): Some
programming languages provide a switch
statement, which allows for the selection of one of
many blocks of code to be executed, based on the
value of an expression.
switch statement
Let’s code an switch statement
First, we will create a function to show what option
is picked
switch statement
Then, we will create a switch statement by using
else-if function
switch statement
Then we will create buttons to execute the switch
statement
switch statement
Then we will create a label to show what statement
is being used
switch statement
•Here is an example of the code
switch statement
•Here is an example of the code
switch statement
When this code is executed, it produce this result
Option 1
Option 2
switch statement
When this code is executed, it produce this result
Option 3
Option 4