Unit 7 - Topic 1 - Selection Structure
Unit 7 - Topic 1 - Selection Structure
Selection Structure
In programming, selection structures allow you to make decisions and execute different code
blocks based on certain conditions. These structures enable your program to choose
between alternative paths of execution, making it possible to create dynamic and responsive
programs. In Python, the most common selection structure is the conditional statement,
which evaluates a condition and executes different code blocks based on the result. This
guide provides an overview of selection structures and explains how to make decisions using
conditional statements in Python.
Conditional Statements
Conditional statements, also known as decision-making statements, evaluate a condition and
execute different sets of statements based on the result. The condition can be a comparison,
logical expression, or any expression that evaluates to either True or False. There are three
main types of conditional statements: if statement, if-else statement, and if-elif-
else statement.
The if Statement
The if statement allows you to execute a block of code only if a specified condition is True.
The syntax of the if statement in Python is as follows:
Conclusion
Selection structures, such as conditional statements, provide essential decision-making
capabilities in Python programming. By using conditional statements, you can control the
flow of your program and execute different code blocks based on specific conditions. This
allows you to create more flexible and dynamic applications. Understanding how to make
decisions using conditional statements is a fundamental skill for every Python programmer.
Activity 1. Write the letter of the correct answer.
A. if statement
B. if-else statement
C. if-elif-else statement
D. decision-making statement
A. if(condition):
B. if condition {
C. if condition:
D. if condition then:
4. Which selection structure is used when you have more than two possible outcomes?
A. if statement
B. if-else statement
C. if-elif-else statement
D. decision-making statement
A. Loop statement
B. Switch statement
C. Conditional statement
D. Assignment statement
A. For statement
B. While statement
C. If statement
D. Function statement
10. What are the three main types of conditional statements in Python?