0% found this document useful (0 votes)
4 views

Conditional statements in Python

The document explains conditional statements in Python, detailing how they control the flow of a program based on specific conditions. It outlines the structure and syntax of 'if', 'if...else', and 'if...elif...else' statements, along with an algorithm for applying for a driving license based on age. Additionally, it introduces the concept of flowcharts as a visual representation of problem-solving steps.

Uploaded by

sathyaa.m1720
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Conditional statements in Python

The document explains conditional statements in Python, detailing how they control the flow of a program based on specific conditions. It outlines the structure and syntax of 'if', 'if...else', and 'if...elif...else' statements, along with an algorithm for applying for a driving license based on age. Additionally, it introduces the concept of flowcharts as a visual representation of problem-solving steps.

Uploaded by

sathyaa.m1720
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

CONDITIONAL STATEMENTS

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.

Algorithm It gives us a better understanding of the


problem and its solution.

Algorithm to apply for a driving license: 1.


Input your age. 2. If your age is greater than
18, you can apply for the license. 3. If it is less
than 18, you are not eligible to apply for
krish_info_tech a driving license.
Flowchart

 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

You might also like