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

Module 6 Decision Making

The document discusses different conditional statements used for decision making in programming including if, if-else, if-elif-else, and switch-case statements. It provides the syntax and examples of using each statement to execute different code blocks based on conditional logic. It also presents a simple calculator program as a project example to demonstrate applying conditional statements.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Module 6 Decision Making

The document discusses different conditional statements used for decision making in programming including if, if-else, if-elif-else, and switch-case statements. It provides the syntax and examples of using each statement to execute different code blocks based on conditional logic. It also presents a simple calculator program as a project example to demonstrate applying conditional statements.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Decision

Making
What is decision making ?
The act or process of deciding something
Based on certain criteria or conditions
Conditional
Statements
Conditional Statements
The most common conditional statements used
for decision-making in programming are
if
if-else
if-elif-else
switch-case
If statement

if

if condition:
# code to be executed if the condition is true
Syntax
The condition is an expression that evaluates to either True or
False. If the condition is true, the indented block of code
under the if statement is executed; otherwise, it is skipped.
if-else Statement

if

el
se
Syntax
If the condition is true, the code block under the if branch is
executed, and the code block under the else branch is skipped.
If the condition is false, the code block under the else branch is
executed, and the code block under the if branch is skipped.

if condition:
# code to be executed if the condition is true
else:
# code to be executed if the condition is false
Example
if-elif-else Statement
if

elif

el
se
if condition1:
# code to be executed if condition1 is true
elif condition2:
# code to be executed if condition2 is true
elif condition3:
# code to be executed if condition3 is true
else:
# code to be executed if none of the conditions are true
Example
Nested if Statements

if
if

els
e

elif

el
se
Example
Simple Calculator Program
(Project)
Create a basic calculator program that
performs addition, subtraction,
multiplication, and division.
Ask the user to enter two numbers and
choose an operation.
Display the result accordingly.
Handle potential errors gracefully.

You might also like