Conditional statements in Python
Conditional statements in Python
IN PYTHON
PLAN OF
CONDITION
ACTION
If your age You are
is greater eligible to
than or apply for a
equal to 18 driving license
Condition
If your age You are not
is less than eligible for a
18 driving license.
krish_info_tech
An algorithm is a well-defined step-by-step
procedure to write a program.
It is a pictorial representation
of steps or procedure to solve
a problem.
Flow chart to check
whether you can apply for a
driving license:
krish_info_tech
In acomputer program, statements
are generally executed
sequentially.
However, the user may need to
change this by repeating or
Control skipping the execution of a few
Statements statements, subject to a given
condition.
In such situation, the flow of control
is altered by the use of Control
Statements.
krish_info_tech
➢ Sequential statements – the
statements in a program are
executed in a sequential manner
➢ Conditional statements – conditional
Types of statements cause the program
control to transfer to a specific
Control section of the program, depending
Structures on the outcome of the conditional
expression.
➢ Iterative statements - it enable the
execution of a set of statements to be
repeated until the condition is true.
krish_info_tech
If statement
Conditional
statements If....else statement
in Python
If....elif...else statement
krish_info_tech
if statement
An if statement comprises of a
boolean condition followed
by one or more statements to
be executed according to the
situation.
Syntax:
if<condition>:
krish_info_tech statement(s)
Example for if statement:
krish_info_tech
if...else statement
Syntax:
if<condition>:
Statement(s) set 1
else:
Statement(s) set 2
krish_info_tech
Example for if...else statement:
krish_info_tech
If...elif...else statement
Syntax:
if<condition1>:
Statement(s) set 1
elif<condition2>:
Statement(s) set 2
else:
Statement(s) set 3
krish_info_tech
Example for If...elif...else statement:
krish_info_tech