3. • Decision making is anticipation of conditions occurring while execution of the
program and specifying actions taken according to the conditions.
• Decision structures evaluate multiple expressions which produce TRUE or FALSE as
outcome.
• Decision-making statements in programming languages decide the direction(Control
Flow) of the flow of program execution.
• Python programming language assumes any non-zero and non-null values as TRUE,
and if it is either zero or null, then it is assumed as FALSE value.
Python - Decision Making
Prof. Percival A. Fernandez
4. Types of Control Flow in Python
In Python programming language,
the type of control flow statements are as follows:
1.The if statement
2.The if-else statement
3.The nested-if statement
4.The if-elif-else ladder
Prof. Percival A. Fernandez
Python - Decision Making
5. Python programming language provides following types of decision making
statements
Prof. Percival A. Fernandez
Python - Decision Making
6. ❖ if statement
The if statement is the most simple decision-making statement. It is used to decide
whether a certain statement or block of statements will be executed or not.
Syntax:
Prof. Percival A. Fernandez
Python - Decision Making
7. ❖ if statement
• Here, the condition after evaluation will be either true or false. if the statement
accepts boolean values
• – if the value is true then it will execute the block of statements below it
otherwise not.
• As we know, python uses indentation to identify a block. So the block under an if
statement will be identified as shown in the below example:
Prof. Percival A. Fernandez
Python - Decision Making
9. ❖ if statement - Flowchart of Python if statement
Prof. Percival A. Fernandez
Python - Decision Making
10. ❖ if statement - Example
Prof. Percival A. Fernandez
Python - Decision Making
11. ❖ if-else statement
• The if statement alone tells us that if a condition is true it will execute a block of
statements and if the condition is false it won’t.
• But if we want to do something else if the condition is false, we can use
the else statement with if statement to execute a block of code when the if condition
is false.
Syntax:
Prof. Percival A. Fernandez
Python - Decision Making
12. Python - Decision Making
❖ if-else statement - Flowchart of Python if statement
Prof. Percival A. Fernandez
13. ❖ if-else statement - Example
Prof. Percival A. Fernandez
Python - Decision Making
14. ❖ nested-if statement
• A nested if is an if statement that is the target of another if statement.
• Nested if statements mean an if statement inside another if statement.
• Yes, Python allows us to nest if statements within if statements. i.e, we can
place an if statement inside another if statement.
Syntax:
Prof. Percival A. Fernandez
Python - Decision Making
15. ❖ nested-if statement - Flowchart of Python Nested if Statement
Prof. Percival A. Fernandez
Python - Decision Making
16. ❖ nested-if statement –
❖ Flowchart of Python
❖ Nested if Statement
Prof. Percival A. Fernandez
Python - Decision Making
17. ❖ nested-if statement - Example
Prof. Percival A. Fernandez
Python - Decision Making
18. ❖ if-elif-else ladder
• Here, a user can decide among multiple options. The if
statements are executed from the top down. As soon as
one of the conditions controlling the if is true, the
statement associated with that if is executed, and the
rest of the ladder is bypassed.
• If none of the conditions is true, then the final else
statement will be executed.
Syntax:
Prof. Percival A. Fernandez
Python - Decision Making
19. ❖ if-elif-else ladder –
❖ Flowchart of Python
❖ if-elif-else ladder
Prof. Percival A. Fernandez
Python - Decision Making
20. ❖ if-elif-else ladder –
❖ Flowchart of Python if-elif-else ladder
Prof. Percival A. Fernandez
Python - Decision Making
21. ❖ if-elif-else ladder - Example
Prof. Percival A. Fernandez
Python - Decision Making