UNDERSTANDING
PROGRAMMING
CONCEPTS
SEQUENCE, SELECTION, ITERATION, AND
ALGORITHMIC THINKING
SEQUENCE, SELECTION, AND
ITERATION
• Sequence: The order in which instructions
are executed in a program.
• Selection: Making decisions based on
conditions (e.g., if-else statements).
• Iteration: Repeating a set of instructions
(e.g., loops).
ALGORITHM, DECOMPOSITION,
AND ABSTRACTION
• Algorithm: A step-by-step process to solve
a problem.
• Decomposition: Breaking a complex
problem into smaller, manageable parts.
• Abstraction Ignoring unnecessary details to
focus on key concepts.
WRITING NUMBERS IN
SEQUENCE
• Example of sequence:
• 1 → 2 → 3 → 4 → 5 → 6 → 7 → 8 → 9 → 10
WRITING DAILY ITINERARY IN SEQUENCE
My Daily Itinerary (Logical Order - Sequence)
1. Wake Up – Get out of bed at 6:00 AM.
2. Freshen Up – Brush teeth, take a shower, and get
dressed.
3. Have Breakfast – Eat a healthy meal to start the day.
4. Go to Work/School – Travel to the workplace or school.
5. Attend Classes/Meetings – Participate in scheduled
activities.
6. Lunch Break – Take a break and have lunch.
7. Continue Work/Studies – Resume tasks and complete
WRITING DAILY ITINERARY IN SEQUENCE
My Daily Itinerary (Logical Order - Sequence)
8. Return Home – Travel back home in the evening.
9. Relax & Refresh – Rest, watch TV, or engage in hobbies.
10. Have Dinner – Eat an evening meal with family.
11. Study/Work on Personal Projects – Revise notes or
work on extra tasks.
12. Prepare for Bed – Brush teeth, set alarm, and relax.
13. Sleep – Go to bed at 10:00 PM.
This sequence follows a logical order of events in a day
CASE STUDY: SELECTION
Example:
• Making tea with or without sugar.
• Both options achieve the same outcome
(tea as a beverage).
• This demonstrates how programs can make
choices using selection (if-else).
CASE STUDY: SELECTION
Case Study: Choosing a Mode of Transport to Work
Scenario
John lives in the city and needs to travel to work every morning.
He has multiple transport options available, and regardless of
which option he chooses, he will still reach his workplace.
Options (Selection Process)
1. Public Bus – Takes 30 minutes, costs less but might have
delays.
2. Taxi – Takes 20 minutes, costs more but is more comfortable.
3. Bicycle – Takes 40 minutes, free of cost, and provides exercise.
4. Walking – Takes 60 minutes, free and healthy but slower.
CASE STUDY: SELECTION
Case Study: Choosing a Mode of Transport to Work
Outcome
Regardless of the transport method John selects, he still arrives at
work, achieving the same result. The choice depends on factors
like cost, speed, and comfort, but the final goal remains
unchanged.
Computing Connection (Selection in Programming)
In programming, selection (if-else statements or switch-case)
allows a program to choose from multiple paths while achieving
the same output. For example, a vending machine allows multiple
ways to pay (cash, card, or mobile payment) but still delivers the
same product.
ITERATION IN PROBLEM
SOLVING
Iteration (looping) is used when a task needs to be
repeated multiple times.
Example:
• A program that keeps asking for user input until a
correct answer is given.
PRINTING THE MULTIPLICATION TABLE OF A NUMBER USING ITERATION
Problem Statement
Write a program that takes a number as input and
prints its multiplication table up to 10 using
iteration.
Solution Using Iteration (Looping)
Concept: Iteration (looping) allows the program to
repeatedly execute a block of code until a condition
is met.
PRINTING THE MULTIPLICATION TABLE OF A NUMBER USING ITERATION
# Get user input
num = int(input("Enter a number: "))
# Use a loop to generate the multiplication table
print(f"Multiplication Table for {num}:")
for i in range(1, 11): # Iterates from 1 to 10
print(f"{num} x {i} = {num * i}")
PRINTING THE MULTIPLICATION TABLE OF A NUMBER USING ITERATION
Explanation of Iteration.
The loop (for i in range(1, 11)) repeats the
multiplication operation 10 times.
The iteration starts at i = 1 and ends at i = 10.
Each time, it calculates num * i and prints the
result.
The loop automatically stops when i > 10.
REAL-LIFE EXAMPLE OF ITERATION
Example: Counting Steps While Walking
• Imagine you are counting steps while walking.
• You start from step 1 and keep counting until step
10.
• This process repeats (iteration) until the condition
(reaching step 10) is met.
COMPUTING CONNECTION
Iteration is useful in programming for repeating
tasks efficiently.
It helps in:
• Automating repetitive processes (e.g.,
calculations, searching, sorting).
• Reducing manual effort.
• Making code more efficient and scalable.
PERFORMING A LINEAR
SEARCH
A linear search finds a value in a list by
checking each element one by one.
Example:
• Finding a student's name in a class list.
• Arranging numbers in increasing or
decreasing order.
LOCATING A GIVEN VALUE POSITION IN A
LIST
Problem Statement
Write a program that takes a list of numbers
and a target value as input. The program should
search for the target value in the list and
display its position (index).
Solution Using Linear Search
Concept: Linear search is a simple method to
find a value in a list by checking each element
LOCATING A GIVEN VALUE POSITION IN A
LIST
# Define a list of numbers
numbers = [10, 25, 30, 45, 50, 65, 80]
# Get user input for the target value
target = int(input("Enter the number to find: "))
# Linear search to locate the position
found = False # Flag to check if the number is found
for index in range(len(numbers)): # Iterate through the list
if numbers[index] == target:
print(f"Number {target} found at position {index}") #
LOCATING A GIVEN VALUE POSITION IN A
LIST
found = True
break # Stop searching once found
# If the number is not found
if not found: print("Number not found in the list.")
LOCATING A GIVEN VALUE POSITION IN A
LIST
Example Run
Input: the number to find: 45
Output: Number 45 found at position 3
LOCATING A GIVEN VALUE POSITION IN A
LIST
Explanation of the Solution
1. The list numbers contains some values.
2. The user enters a target number to find.
3. A loop iterates through the list, checking each value.
4. If the number is found, it prints its index (position)
and stops.
5. If the number is not found, a message is displayed.
LOCATING A GIVEN VALUE POSITION IN A
LIST
Real-Life Example of Locating a Value
• Looking for a specific contact name in your
phonebook.
• Searching for a product price in a supermarket list.
• Finding a page number in a book index.
ARRANGING GIVEN VALUES IN
INCREASING AND DECREASING ORDER
Problem Statement
Write a program that takes a list of numbers
and arranges them in increasing (ascending)
order and decreasing (descending) order.
Solution Using Python
Python provides the sort() method for in-place
sorting and the sorted() function for sorting
without modifying the original list.
ARRANGING GIVEN VALUES IN
INCREASING AND DECREASING ORDER
# Define a list of numbers
numbers = [50, 10, 30, 80, 60, 25, 45]
# Sort the list in increasing (ascending) order
ascending_order = sorted(numbers)
# Sort the list in decreasing (descending) order
descending_order = sorted(numbers, reverse=True)
# Display results
print("Original List:", numbers)
print("Ascending Order:", ascending_order)
ARRANGING GIVEN VALUES IN
INCREASING AND DECREASING ORDER
Example Run
Output:
Original List: [50, 10, 30, 80, 60, 25, 45]
Ascending Order: [10, 25, 30, 45, 50, 60, 80]
Descending Order: [80, 60, 50, 45, 30, 25, 10]
ARRANGING GIVEN VALUES IN
INCREASING AND DECREASING ORDER
Explanation of the Solution
1. A list numbers is defined with unordered values.
2. The sorted() function is used to arrange the list
in:
• Ascending order (smallest to largest).
• Descending order (largest to smallest).
3. The original list remains unchanged.
4. The sorted results are displayed.
ARRANGING GIVEN VALUES IN
INCREASING AND DECREASING ORDER
Real-Life Examples of Sorting
1. Sorting students' test scores from lowest to
highest
2. Arranging products by price in a shopping
app
3. Sorting names alphabetically in a contact list