100% found this document useful (1 vote)
176 views4 pages

Unit 7 - Topic 1 - Selection Structure

Selection structures allow programs to make decisions and execute different code blocks based on conditions being true or false. The most common selection structure in Python is the conditional statement, which evaluates a condition and executes code accordingly. There are three main types of conditional statements in Python: if statements execute code if a condition is true; if-else statements add alternative code for when conditions are false; and if-elif-else statements sequentially evaluate multiple conditions and code blocks.

Uploaded by

Blade of Despair
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
100% found this document useful (1 vote)
176 views4 pages

Unit 7 - Topic 1 - Selection Structure

Selection structures allow programs to make decisions and execute different code blocks based on conditions being true or false. The most common selection structure in Python is the conditional statement, which evaluates a condition and executes code accordingly. There are three main types of conditional statements in Python: if statements execute code if a condition is true; if-else statements add alternative code for when conditions are false; and if-elif-else statements sequentially evaluate multiple conditions and code blocks.

Uploaded by

Blade of Despair
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/ 4

UNIT 7 - TOPIC 1

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:

The if-else Statement


The if-else statement extends the if statement by providing an alternative code block to
be executed when the condition is False. The syntax of the if-else statement in Python is as
follows:
The if-elif-else Statement
The if-elif-else statement allows you to evaluate multiple conditions in a sequential
manner. It is used when you have more than two possible outcomes. The syntax of the if-
elif-else 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.

1. Which selection structure evaluates a condition and executes different sets of


statements based on the result?

A. if statement
B. if-else statement
C. if-elif-else statement
D. decision-making statement

2. What is the syntax of the if statement in Python?

A. if(condition):
B. if condition {
C. if condition:
D. if condition then:

3. What does the if-else statement provide in addition to the if statement?

A. An alternative code block to be executed when the condition is False.


B. An option to evaluates multiple conditions in a sequential manner.
C. A way to evaluate a condition and execute different sets of statements based on
the result.
D. A way to execute a block of code only if a specified condition is True.

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

5. Why are selection structures important in Python programming?

A. To evaluate conditions and execute different sets of statements based on the


result.
B. To control the flow of the program and create dynamic applications.
C. To provide essential decision-making capabilities.
D. To make the code more readable and organized.

6. What is the most common selection structure in Python?

A. Loop statement
B. Switch statement
C. Conditional statement
D. Assignment statement

7. Which of the following is a main type of conditional statement in Python?

A. For statement
B. While statement
C. If statement
D. Function statement

8. What does the if statement do?

A. Executes a block of code only if a specified condition is True.


B. Executes a block of code multiple times.
C. Provides an alternative code block to be executed when the condition is False.
D. Allows you to evaluate multiple conditions in a sequential manner.

9. What is the purpose of understanding conditional statements?

A. To control the flow of a program based on specific conditions.


B. To define variables and assign values to them.
C. To organize and structure the code.
D. To loop through a set of code multiple times.

10. What are the three main types of conditional statements in Python?

A. if statement, loop statement, try-except statement


B. if-else statement, while statement, for statement
C. if statement, if-else statement, if-elif-else statement
D. if statement, for statement, except statement

You might also like