Lesson Notes By Weeks and Term v5 - Grade 10

Solution development: algorithmic thinking and introductory programming – Week 3 focus

Download the Lessonotes Mobile South Africa app for faster lesson access on Android and iPhone.

Subject: Information Technology

Class: Grade 10

Term: 2nd Term

Week: 3

Theme: General lesson support

Lesson Video

This page supports the lesson note with a companion video and a short classroom-ready summary.

For class groups and homework, share this lesson page so learners also get the summary, objectives, and full lesson context.

Performance objectives

Lesson summary

This week, we delve deeper into algorithmic thinking and introductory programming, focusing on control structures, specifically sequential execution and selection (IF statements). Understanding these concepts is crucial because algorithms form the backbone of every computer program, and programs are increasingly shaping our world. From managing traffic flow in Johannesburg using complex algorithms to predicting consumer behavior based on data analysis, algorithmic thinking empowers us to solve problems logically and efficiently.

Lesson notes

2.1 Sequential Execution: Sequential execution means instructions are executed in the order they appear, one after the other, from top to bottom. This is the most basic control structure.

Think of following a recipe: you perform each step in the order it's written. In programming, each line of code is executed in sequence unless a control structure (like an IF statement, which we'll cover next) alters this flow.

Importance: Sequential execution ensures predictability. The outcome is determined by the initial state and the sequence of operations. Without it, programs would be chaotic and unpredictable.

Example: Consider a program to calculate the area of a rectangle: ``` Pseudocode INPUT length INPUT width area = length * width OUTPUT area ``` In this example, the steps are executed in the order they appear: first, we get the length from the user, then the width, then we calculate the area, and finally, we display the result. 2.2 Selection (IF Statements): IF statements allow us to make decisions in our programs. They enable the program to execute different blocks of code based on whether a certain condition is true or false. This is also called "conditional branching".

Syntax: Most programming languages (including Python, commonly used in South African schools) use a variation of the following structure: ```python if condition: Code to execute if the condition is true else: Code to execute if the condition is false (optional) ``` Condition: The `condition` is a Boolean expression (an expression that evaluates to either `True` or `False`). Common operators used in conditions include: `==` (equal to) `!=` (not equal to) `>` (greater than) ` =` (greater than or equal to) ` = 1000: discount = 0.10 # 10% discount elif amount_spent >= 500: discount = 0.05 # 5% discount else: discount = 0.00 # No discount discount_amount = amount_spent * discount final_amount = amount_spent - discount_amount print("Discount amount: R", discount_amount) # Print with currency format print("Final amount: R", final_amount) ``` Explanation: This program uses `elif` statements to check multiple conditions. If the amount spent is R1000 or more, a 10% discount is applied. If it's R500 or more (but less than R1000), a 5% discount is applied. Otherwise, no discount is applied. This simulates common practices in South African retail stores and online shops. Guided Practice (With Solutions)

Question 1: Write a program that takes a student's test score as input and prints "Pass" if the score is 50 or greater, and "Fail" otherwise.

Solution: ```python score = int(input("Enter the student's score: ")) if score >= 50: print("Pass") else: print("Fail") ```

Commentary: This simple example demonstrates the basic structure of an IF statement. The condition `score >= 50` checks if the score is greater than or equal to

5

0. If it is, the code inside the `if` block (printing "Pass") is executed. Otherwise, the code inside the `else` block (printing "Fail") is executed.

Question 2: Write a program that takes two numbers as input and prints the larger of the two.

Solution: ```python num1 = float(input("Enter the first number: ")) num2 = float(input("Enter the second number: ")) if num1 > num2: print(num1, "is larger than", num2) else: print(num2, "is larger than or equal to", num1) #Includes handling of equal numbers ```

Commentary: This example shows how to compare two values using the `>` operator. It also illustrates that we can't assume only one condition will be met. We must consider all possibilities. Here we include equal numbers by stating 'is larger than or equal to'.

Question 3: Write a program that takes a temperature in Celsius as input and prints "Freezing" if the temperature is below 0, "Comfortable" if the temperature is between 20 and 30 (inclusive), and "Hot" otherwise.

Solution: ```python temperature = float(input("Enter the temperature in Celsius: ")) if temperature = 20 and temperature = 20 and temperature 10: discount = 0.10 * total_cost total_cost -= discount print("You qualified for a discount of: R",discount) #Print Discount else: discount = 0 #If no discount, set discount amount to zero print("Total expense: R", total_cost) #Print total cost regardless if discount was applied ```

Commentary: This problem integrates both sequential processing (getting input, calculating cost) and conditional selection (applying discount). Notice the discount calculation and application are only done if the condition is true. Always ensure variable usage (discount) is initialised correctly if not all branches lead to it being set, which is why `discount=0` is included in the else statement. Independent Practice (Questions Only) Write a program that takes a student's age as input. If the age is less than 18, print "Minor". If the age is between 18 and 65 (inclusive), print "Adult". Otherwise, print "Senior". Write a program that takes three numbers as input and prints the largest of the three.