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

CT8(Q4)ControlStructure

This document outlines the learning objectives and competencies related to control structures in programming, specifically in Python. It explains the concept of control structures, including sequential, selection, and repetition types, and provides examples of each. Additionally, it includes practical exercises for students to apply their understanding through coding tasks and evaluations.

Uploaded by

danielle.tantoco
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

CT8(Q4)ControlStructure

This document outlines the learning objectives and competencies related to control structures in programming, specifically in Python. It explains the concept of control structures, including sequential, selection, and repetition types, and provides examples of each. Additionally, it includes practical exercises for students to apply their understanding through coding tasks and evaluations.

Uploaded by

danielle.tantoco
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

TECHNOLOGY LIVELIHOOD EDUCATION

Creative Technologies 8
Quarter 4 | Control Structure

Learning Competencies (Essential Competencies)

• Describe how control structure is used in programming. (SSP_TLE-CT8AP

– IId-m-3.1)

Objectives

At the end of this lesson, students should be able to:

• Demonstrate understanding the concept of a control structure in

programming;

• Identify the different types of control structure in Python and

• Write codes using control structures.

Let’s Understand

When a program is running, the code is being read by the computer line by

line (from top to bottom, and for the most part left to right), just like you would

read a book. This is known as the “code flow“, now as the code is being read from

top to bottom, it may hit a point where it needs to make a decision, this decision

could make the code jump to a completely different part of the program, or it could

make it re-run a certain piece again, or just plain skip a bunch of code. You could

think of this process like if you were to read and choose your own adventure book, you

get to page 4 of the book, and it says “if you want to do X, turn to page 14, if you want

to do Y, turn to page 5″. That decision that must be made by the reader is the

same decision that the computer program must make, only the computer program
has a strict set of rules to decide which direction to go (whereas if you were

reading a book, it would be a subjective choice based on whomever is reading the

book). So, this decision that must be made, that will in turn effect the flow of code,

is known as a control structure!

A control structure is a block of programming that analyzes

variables and chooses a direction in which to go based on given parameters. The

term flow control details the direction the program takes (which way program control

“flows”). Hence it is the basic decision-making process in computing; flow

control determines how a computer will respond when given certain conditions and

parameters.

The control flow of a Python program is regulated by conditional statements,

loops, and function calls.

Python has three types of control structures:

• Sequential - default mode

• Selection / Conditional - used for decisions and branching

• Repetition - used for looping, i.e., repeating a piece of code multiple times.

1. Sequential

Sequential statements are a set of statements whose execution process

happens in a sequence. The problem with sequential statements is that if the

logic has broken in any one of the lines, then the complete source code

execution will break.


2. Selection/Decision control statements

In Python, the selection statements are also known as Decision control

statements or branching statements.

The selection statement allows a program to test several conditions and execute

instructions based on which condition is true.

Some Decision Control Statements are:

• Simple if

• if-else

• nested if

• if-elif-else

Simple if: If statements are control flow

statements that help us to run a particular code,

but only when a certain condition is met or

satisfied. A simple if only has one condition to

check.
if-else: The if-else statement evaluates the condition and will execute the body of if if

the test condition is True, but if the condition is False,

then the body of else is executed.

nested if: Nested if statements are an if statement inside another if statement.


if-elif-else: The if-elif-else statement is used to conditionally execute a statement or a

block of statements.
3. Repetition

A repetition statement is used to repeat a group(block) of programming

instructions.

In Python, we generally have two loops/repetitive statements:

• for loop

• while loop

for loop: A for loop is used to iterate

over a sequence that is either a list,

tuple, dictionary, or a set. We can

execute a set of statements once for

each item in a list, tuple, or

dictionary.

while loop: In Python, while loops are used to execute a block of statements

repeatedly until a given condition is satisfied. Then, the expression is checked again

and, if it is still true, the body is executed again. This continues until the expression

becomes false.
Let’s Apply

Direction: Watch the video about Python Programming Tutorial – Control

Structures and write the codes given in the example and save it with the

corresponding filename below. Submit the three programs in the Google Classroom.

Link: https://www.youtube.com/watch?v=kIPpTYjareA

1. Filename: classnumber_sequential

2. Filename: classnumber_selection
3. Filename: classnumber_repetition

Let’s Analyze

Direction: Write the following codes in Python and save according to its

corresponding filename. Run the code and take a screenshot of the output.

The text editor and console should be included.

1. Filename: classnumber_py1

2. Filename: classnumber_py2

3. Filename: classnumber_py3
4. Filename: classnumber_py4

5. Filename: classnumber_py5

Let’s Try (Evaluation)

Direction: Read the questions carefully and select the letter of the

correct answer in the Google Form.

1. Which control structure will execute an instruction only after the computer

evaluates conditions to determine if a certain condition exists?


a. selection b. loop

b. sequence d. function

2. What are the three main programming structures?

a. Sequence, selection, iteration

b. Java, Python, Visual Basic

c. Machine, assembly, high-level

d. Structured, object-oriented, procedural

3. Which type of statement is an example of a selection programming structure?

a. If/else

b. While

c. do while

d. for

4. A grocery store manager wants a program that allows the clerk to enter original

price of an item and discount rate. The program then should display both the

original and discounted price.

a. Selection

b. Iteration

c. Sequence

d. All of the choices

5. Jackson has written a section of code in his program that instructs a character to

move forward unless it encounters an obstacle, such as a rock. If the character

encounters an obstacle, then it should change direction before moving forward

again. If it does not encounter an obstacle, it should continue moving forward.

Which type of control structure has Jackson written?


a. selection b. loop

b. sequence d. function

Let’s Create

Direction: Write the codes for the following program. Submit your

Python codes in the Google Classroom.

1. Create a program that accepts two inputs of weight from the user and prints

which weight is bigger. Filename is classnumber_create1.

2. Create a program that accept an integer grade from the user. If the grade is

below 83, then it should display the message in the screen “You did not meet

the grade requirement”. If the grade is greater than 83, then it should display

the message in the screen “Congratulations! You passed!”. Filename is

classnumber_create2.

References:

https://www.coderscampus.com/the-5-basic-concepts-of-any-programming-language-
concept-2/
https://www.kidscodecs.com/programming-control-flows/
https://www.educative.io/edpresso/what-are-control-flow-statements-in-python

You might also like