Module 6 Decision Making
Module 6 Decision Making
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.