0% found this document useful (0 votes)
14 views22 pages

Year 10 Coding Note

Uploaded by

adeyemititomi
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
0% found this document useful (0 votes)
14 views22 pages

Year 10 Coding Note

Uploaded by

adeyemititomi
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/ 22

YEAR 10 CHRISTMAS TERM CODING NOTE

WEEK ONE: Introduction to Python Programming

Objectives Keywords:

• Understand the fundamentals of Python • Python: A high-level, interpreted programming


programming, including syntax and language known for its readability and
semantics. versatility.
• Learn how to write and execute basic • Variable: A named storage location that holds a
Python programs. value, which can be changed during program
• Develop skills in using variables, data execution.
types, and basic input/output operations. • Data Type: Classification of data that
determines the kind of value a variable can hold
(e.g., integer, float, string, boolean).
• Function: A reusable block of code that
performs a specific task, defined using the def
keyword.
• Input/Output: Methods for receiving user input
and displaying results (using input() and
print() functions).

Theory:

Python is a powerful programming language that emphasizes readability and simplicity. It is widely used for
various applications, including web development, data analysis, artificial intelligence, and more.

1. Basic Syntax: Python uses indentation to define blocks of code. Statements end with a newline
rather than a semicolon.
2. Variables and Data Types:
o Variables are created when you assign a value to them.
o Common data types include:
▪ Integer: Whole numbers (e.g., 5)
▪ Float: Decimal numbers (e.g., 3.14)
▪ String: Text enclosed in quotes (e.g., "Hello, World!")
▪ Boolean: Represents True or False.
3. Input and Output:
o Use the print() function to display output.
o Use the input() function to receive input from the user.
4. Functions: Functions are defined using the def keyword and can take parameters and return values.

Practical Classwork:

Task: Write a simple Python program that calculates the area of a rectangle based on user input for width
and height.

Instructor: Mr. Faith FAS 1


YEAR 10 CHRISTMAS TERM CODING NOTE

Solution (Python Implementation):

# Function to calculate the area of a rectangle


def calculate_area(width, height):
return width * height

# Taking user input


width = float(input("Enter the width of the rectangle: "))
height = float(input("Enter the height of the rectangle: "))

# Calculating the area


area = calculate_area(width, height)

# Displaying the result


print(f"The area of the rectangle is: {area}")

When executed, this program will prompt the user for the width and height and then display the calculated
area.

Homework:

1. Task 1: Write a Python program that prompts the user for their name and age, then outputs a
message stating the user's name and how old they will be in 10 years.

Steps:

o Use input() to get the user's name and age.


o Calculate the future age by adding 10 to the current age.
o Use print() to display the message.
2. Task 2: Create a function called greet_user that takes a name as a parameter and prints a
personalized greeting.

Instructions for Homework Submission:

• Include both Python implementations in your submission.


• Ensure to add comments in your code explaining each part.
• Submit your Python files or screenshots of the output in the next class for review and discussion.

Instructor: Mr. Faith FAS 2


YEAR 10 CHRISTMAS TERM CODING NOTE

WEEK TWO

Topic: Control Flow: Conditionals and Loops

Objectives: Keywords:

• Understand the concepts of conditionals • Conditional Statement: A statement that


and loops in Python programming. executes a block of code based on a condition
• Learn how to implement decision-making (e.g., if, elif, else).
using if, elif, and else statements. • Loop: A construct that allows repeated
• Develop skills in creating loops using for execution of a block of code (e.g., for loop,
and while constructs for repeated while loop).
execution of code. • Boolean Expression: An expression that
evaluates to either True or False.
• Iteration: The process of repeating a set of
instructions.

Theory:

In Python, conditionals and loops are fundamental concepts that allow for dynamic program behavior.

1. Conditionals:
o Used to perform different actions based on varying conditions.
o The basic structure includes:

python
Copy code
if condition:
# code to execute if condition is True
elif another_condition:
# code to execute if the second condition is True
else:
# code to execute if neither condition is True

Example:

age = 18
if age < 18:
print("You are a minor.")
elif age == 18:
print("You are just an adult.")
else:
print("You are an adult.")

2. Loops:
o For Loop: Used for iterating over a sequence (like a list or string).

python
Copy code
for item in sequence:

Instructor: Mr. Faith FAS 3


YEAR 10 CHRISTMAS TERM CODING NOTE

# code to execute for each item

Example:

for i in range(5):
print(f"Iteration {i + 1}")

o While Loop: Continues execution as long as the specified condition is True.

while condition:
# code to execute as long as condition is True

Example:

count = 0
while count < 5:
print(f"Count is {count}")
count += 1

Practical Classwork:

Task: Write a Python program that prompts the user to enter a number and checks if it is even or odd, then
uses a loop to print all even numbers from 0 to that number.

Solution (Python Implementation):

# Function to check if a number is even or odd


def check_even_odd(num):
if num % 2 == 0:
return "even"
else:
return "odd"

# Taking user input


user_number = int(input("Enter a number: "))
result = check_even_odd(user_number)
print(f"The number {user_number} is {result}.")

# Loop to print even numbers


print("Even numbers from 0 to", user_number, ":")
for i in range(0, user_number + 1, 2):
print(i)

When executed, this program will prompt the user for a number, indicate whether it is even or odd, and then
print all even numbers up to that number.

Homework:

1. Task 1: Write a Python program that takes a number as input and prints whether it is positive,
negative, or zero.

Instructor: Mr. Faith FAS 4


YEAR 10 CHRISTMAS TERM CODING NOTE

Steps:

o
Use an if statement to check the number.
o
Print the appropriate message based on the condition.
2. Task 2: Create a program that uses a while loop to calculate the factorial of a given positive integer.

Instructions for Homework Submission:

• Include both Python implementations in your submission.


• Ensure to add comments in your code explaining each part.
• Submit your Python files or screenshots of the output in the next class for review and discussion.

WEEK THREE

Topic: Functions and Modular Programming

Objectives: Keywords:

• Understand the concept and importance of • Function: A block of reusable code that performs a
functions in Python programming. specific task, defined using the def keyword.
• Learn how to create reusable code using • Parameter: A variable in a function definition that
functions and modular programming. accepts input values.
• Develop skills in defining and calling • Return Value: The value that a function outputs
functions with parameters and return values. after execution, specified using the return
keyword.
• Modular Programming: A programming paradigm
that emphasizes separating a program into smaller,
manageable, and reusable modules or functions.

Theory:

Functions are essential for writing organized and maintainable code. They allow programmers to break
down complex problems into smaller, more manageable tasks. A function is defined using the def keyword,
followed by the function name and parentheses, which may include parameters.

1. Defining a Function:

python
Copy code
def function_name(parameters):
# code block
return value

Example:

python

Instructor: Mr. Faith FAS 5


YEAR 10 CHRISTMAS TERM CODING NOTE
Copy code
def add_numbers(a, b):
return a + b

2. Calling a Function: To use a function, you call it by its name and provide the necessary arguments.

python
Copy code
result = add_numbers(5, 3)
print(result) # Output: 8

3. Benefits of Functions:
o Code Reusability: Functions can be called multiple times, reducing code duplication.
o Modularity: Programs can be structured into smaller sections, making them easier to understand
and maintain.
o Abstraction: Functions allow users to focus on the task at hand without worrying about the
implementation details.

Practical Classwork:

Task: Write a Python program that defines a function to calculate the area of a rectangle, and then calls that
function with user-provided dimensions.

Solution (Python Implementation):

python
Copy code
# Function to calculate the area of a rectangle
def calculate_area(width, height):
return width * height

# Taking user input


width = float(input("Enter the width of the rectangle: "))
height = float(input("Enter the height of the rectangle: "))

# Calling the function and displaying the result


area = calculate_area(width, height)
print(f"The area of the rectangle is: {area}")

When executed, this program prompts the user for the width and height of a rectangle and displays the
calculated area.

Homework:

1. Task 1: Write a Python program that defines a function to check if a number is prime. The function
should return True if the number is prime and False otherwise.

Steps:

o Implement a function named is_prime that accepts a number as a parameter.


o Use a loop to check for factors of the number.
o Return True or False based on the checks.
2. Task 2: Create a program that defines a function to convert Celsius to Fahrenheit and vice versa
based on user input. Allow the user to specify which conversion they would like to perform.

Instructor: Mr. Faith FAS 6


YEAR 10 CHRISTMAS TERM CODING NOTE

Instructions for Homework Submission:

• Include both Python implementations in your submission.


• Ensure to add comments in your code explaining each part.
• Submit your Python files or screenshots of the output in the next class for review and discussion.

WEEK FOUR: Lists and Tuples

Learning Objectives:

• Understand the difference between lists and tuples.


• Learn how to create and manipulate lists and tuples.
• Apply indexing, slicing, and basic operations on lists and tuples.

Keywords:

• List, Tuple, Indexing, Slicing, Immutability

Introduction:

Lists and tuples are two of the most commonly used data structures in Python. Both store collections of items, but
while lists are mutable (can be changed), tuples are immutable (cannot be changed after creation).

Theory Contents:

1. Lists:
o A list is a collection of items enclosed in square brackets.
o Lists are mutable, meaning items can be added, removed, or modified.
o Common operations: append, insert, pop, remove, index, slice.

Example:

my_list = [1, 2, 3, "apple", "banana"]

my_list.append(4)

print(my_list) # Output: [1, 2, 3, "apple", "banana", 4]

2. Tuples:
o A tuple is a collection of items enclosed in parentheses.
o Tuples are immutable, meaning once created, they cannot be changed.

Example:

my_tuple = (1, 2, 3, "apple", "banana")

print(my_tuple[0]) # Output: 1

Instructor: Mr. Faith FAS 7


YEAR 10 CHRISTMAS TERM CODING NOTE

3. Key Differences:
o Lists are mutable, tuples are immutable.
o Lists are generally used for collections that need to be modified, while tuples are used for fixed
collections.

Practical Content:

Example:

# Creating a list and a tuple

my_list = [1, 2, 3, "apple", "banana"]

my_tuple = (1, 2, 3, "apple", "banana")

# Accessing elements

print(my_list[0]) # Output: 1

print(my_tuple[0]) # Output: 1

# Modifying the list

my_list[0] = "orange"

print(my_list) # Output: ["orange", 2, 3, "apple", "banana"]

# Tuples cannot be modified

# my_tuple[0] = "orange" # This will raise an error

Practical Class Task:

1. Create a list and a tuple that contains names of 5 fruits.


2. Add another fruit to the list but try to add one to the tuple (observe the result).

Solution:

fruits_list = ["apple", "banana", "cherry", "date", "elderberry"]

fruits_tuple = ("apple", "banana", "cherry", "date", "elderberry")

# Adding a fruit to the list

Instructor: Mr. Faith FAS 8


YEAR 10 CHRISTMAS TERM CODING NOTE

fruits_list.append("fig")

# Trying to add to the tuple (this will raise an error)

# fruits_tuple.append("fig") # Tuples don't have append

Individual Task:

Write a Python program to create a list of 10 numbers. Perform slicing to print only the first 5 numbers and the last 3
numbers.

Assignment:

Write an essay comparing lists and tuples in Python, providing at least two examples where each would be more
suitable.

WEEK FIVE: Dictionaries and Sets

Learning Objectives:

• Understand the structure of dictionaries and sets.


• Learn how to create, access, and manipulate dictionaries and sets.
• Understand the use cases of dictionaries and sets in Python.

Keywords:

• Dictionary, Set, Key-Value Pair, Hashing, Uniqueness

Introduction:

Dictionaries and sets are both used to store collections of items, but they function differently. Dictionaries store key-
value pairs, while sets store unique elements in an unordered manner.

Theory Contents:

1. Dictionaries:
o A dictionary is a collection of key-value pairs, where each key is unique.
o They are mutable and can store any type of data as values.

Example:

student = {"name": "John", "age": 21, "major": "Computer Science"}

print(student["name"]) # Output: John

Instructor: Mr. Faith FAS 9


YEAR 10 CHRISTMAS TERM CODING NOTE

2. Sets:
o A set is an unordered collection of unique elements.
o Sets are useful when you need to store only unique items and do not care about the order.

Example:

my_set = {1, 2, 3, 3, 4}

print(my_set) # Output: {1, 2, 3, 4} (duplicates are removed)

3. Key Differences:
o Dictionaries store data as key-value pairs, while sets store only unique elements.
o Sets do not allow duplicates, but dictionaries can have duplicate values (though not duplicate keys).

Practical Content:

Example:

# Creating a dictionary

student = {"name": "John", "age": 21, "major": "Computer Science"}

# Accessing values

print(student["age"]) # Output: 21

# Creating a set

numbers = {1, 2, 2, 3, 4}

print(numbers) # Output: {1, 2, 3, 4} (duplicates are removed)

Practical Class Task:

1. Create a dictionary that contains information about 3 students (name, age, grade).
2. Create a set of 5 unique numbers.

Solution:

# Dictionary of students

students = {

"student1": {"name": "Alice", "age": 20, "grade": "A"},

"student2": {"name": "Bob", "age": 21, "grade": "B"},

Instructor: Mr. Faith FAS 10


YEAR 10 CHRISTMAS TERM CODING NOTE

"student3": {"name": "Charlie", "age": 22, "grade": "C"}

# Set of unique numbers

unique_numbers = {1, 2, 3, 4, 5}

Individual Task:

Write a Python program to create a set of the first 10 even numbers and another set of the first 10 odd numbers.
Perform a union and intersection of the two sets.

Assignment:

Write an essay explaining the advantages of using dictionaries and sets, with practical examples of each.

WEEK SIX: File Handling

Learning Objectives:

• Learn how to open, read, write, and close files in Python.


• Understand different modes of file handling: read, write, append, etc.
• Apply file handling techniques in a Python program.

Keywords:

• File, Open, Read, Write, Append, File Pointer

Introduction:

File handling in Python allows you to work with files, enabling you to read from and write to files. Files are useful for
storing data permanently.

Theory Contents:

1. Opening a File:
o Use the open() function to open a file.
o Modes: "r" (read), "w" (write), "a" (append), "r+" (read and write).

Example:

file = open("example.txt", "r")

2. Reading and Writing:


o The read() method reads the content of a file.
o The write() method writes content to a file.

Instructor: Mr. Faith FAS 11


YEAR 10 CHRISTMAS TERM CODING NOTE

Example:

file = open("example.txt", "w")

file.write("Hello, world!")

file.close()

3. Closing a File:
o Always close a file after performing operations to free up system resources.
o Use file.close() to close the file.

Practical Content:

Example:

# Writing to a file

file = open("data.txt", "w")

file.write("This is a test file.")

file.close()

# Reading from a file

file = open("data.txt", "r")

content = file.read()

print(content) # Output: This is a test file.

file.close()

Practical Class Task:

1. Create a text file and write a list of 5 of your favorite movies into it.
2. Read the contents of the file and print it to the console.

Solution:

# Writing to a file

file = open("movies.txt", "w")

file.write("Inception\nThe Matrix\nInterstellar\nAvatar\nThe Dark Knight")

file.close()

Instructor: Mr. Faith FAS 12


YEAR 10 CHRISTMAS TERM CODING NOTE

# Reading the file

file = open("movies.txt", "r")

print(file.read())

file.close()

Individual Task:

Create a Python program that reads a file containing a list of student names and writes only those names that start
with the letter "A" to a new file.

Assignment:

Write an essay on the importance of file handling in Python, with examples of real-world applications.

WEEK EIGHT: Introduction to Algorithms

Learning Objectives:

• Understand what an algorithm is and why it's important.


• Learn how to create simple algorithms.
• Understand the basic steps involved in writing an algorithm.

Keywords:

• Algorithm, Pseudocode, Flowchart, Steps, Efficiency

Introduction:

An algorithm is a step-by-step procedure used to solve a problem or accomplish a task. In computer science,
algorithms form the foundation of programming.

Theory Contents:

1. What is an Algorithm?
o An algorithm is a sequence of well-defined instructions to solve a problem.
o It should be finite, unambiguous, and effective.

Example of an algorithm to make tea:

3. Boil water.
4. Add tea leaves to the boiling water.
5. Pour the water into a cup.

Instructor: Mr. Faith FAS 13


YEAR 10 CHRISTMAS TERM CODING NOTE

6. Add sugar and milk.


2. Algorithm Representation:
o Pseudocode: A high-level representation of an algorithm using plain English.
o Flowchart: A diagram that represents the sequence of steps in an algorithm.

Example of pseudocode:

START

INPUT two numbers, A and B

IF A > B THEN

PRINT A

ELSE

PRINT B

ENDIF

END

3. Importance of Algorithms:
o Algorithms help break down complex problems into smaller, manageable steps.
o Efficient algorithms improve the performance of programs.

Practical Content:

Example:

# Algorithm to find the largest of two numbers

def find_largest(a, b):

if a > b:

return a

else:

return b

# Test the algorithm

result = find_largest(10, 20)

print(result) # Output: 20

Instructor: Mr. Faith FAS 14


YEAR 10 CHRISTMAS TERM CODING NOTE

Practical Class Task:

1. Write a Python function that takes two numbers as input and returns the larger of the two.
2. Write pseudocode for an algorithm that finds the sum of the first 10 numbers.

Solution:

# Function to find the largest of two numbers

def find_largest(a, b):

if a > b:

return a

else:

return b

# Example usage

print(find_largest(5, 10)) # Output: 10

Individual Task:

Write a Python function that calculates the factorial of a number using an algorithm. Provide both the code and the
pseudocode.

Assignment:

Write an essay on the importance of algorithms in software development, and provide an example of a sorting
algorithm in pseudocode.

WEEK NINE: Complex Data Structures

Learning Objectives:

• Understand the structure and use of complex data structures like stacks, queues, and trees.
• Learn how to implement basic operations on stacks, queues, and trees in Python.
• Apply complex data structures in solving real-world problems.

Keywords:

• Stack, Queue, Tree, Linked List, Node, LIFO, FIFO

Instructor: Mr. Faith FAS 15


YEAR 10 CHRISTMAS TERM CODING NOTE

Introduction:

Complex data structures like stacks, queues, and trees are used to solve more advanced problems in computer
science. Each structure has its own set of rules for how data is stored and accessed.

Theory Contents:

1. Stacks:
o A stack is a linear data structure that follows the Last In, First Out (LIFO) principle.
o Operations: push (add), pop (remove).

Example:

stack = []

stack.append(1)

stack.append(2)

print(stack.pop()) # Output: 2

2. Queues:
o A queue is a linear data structure that follows the First In, First Out (FIFO) principle.
o Operations: enqueue (add), dequeue (remove).

Example:

queue = []

queue.append(1)

queue.append(2)

print(queue.pop(0)) # Output: 1

3. Trees:
o A tree is a hierarchical data structure consisting of nodes, where each node has a value and
references to its children.
o The top node is called the root.

Example (binary tree):

class Node:

def __init__(self, value):

self.value = value

self.left = None

self.right = None

Instructor: Mr. Faith FAS 16


YEAR 10 CHRISTMAS TERM CODING NOTE

root = Node(1)

root.left = Node(2)

root.right = Node(3)

Practical Content:

Example:

# Implementing a stack

stack = []

# Adding elements to the stack

stack.append("book1")

stack.append("book2")

# Removing the last element

print(stack.pop()) # Output: "book2"

Practical Class Task:

1. Implement a stack in Python and perform push and pop operations.


2. Create a queue in Python and add 5 elements, then remove the first one added.

Solution:

# Stack example

stack = []

stack.append(10)

stack.append(20)

stack.pop() # Output: 20

Individual Task:

Write a Python program to create a binary tree and traverse it in pre-order, in-order, and post-order.

Instructor: Mr. Faith FAS 17


YEAR 10 CHRISTMAS TERM CODING NOTE

Assignment:

Write an essay on the use of complex data structures in real-world applications, providing examples for each.

WEEK TEN: Algorithm Efficiency and Big-O Notation

Learning Objectives:

• Understand the concept of algorithm efficiency and how it affects program performance.
• Learn about Big-O Notation and how it is used to analyze algorithm complexity.
• Apply Big-O Notation to simple algorithms to determine their time and space complexity.

Keywords:

• Algorithm Efficiency, Big-O Notation, Time Complexity, Space Complexity

Introduction:

Algorithm efficiency refers to how quickly and effectively an algorithm solves a problem, particularly as the size of
the input grows. Big-O Notation is used to describe the worst-case performance of an algorithm.

Theory Contents:

1. Big-O Notation:
o Big-O Notation is used to describe how the runtime or space requirements of an algorithm grow as
the input size increases.
o Common Big-O classes: O(1), O(n), O(n^2), O(log n), etc.

Example of time complexity:

o O(1): Constant time (e.g., accessing an array element).


o O(n): Linear time (e.g., iterating over an array).
2. Analyzing Algorithms:
o When analyzing an algorithm, consider both the time complexity (how long it takes) and the space
complexity (how much memory it uses).
3. Importance of Efficiency:
o Efficient algorithms are crucial for large-scale applications, where even small improvements in
performance can save significant time and resources.

Practical Content:

Example:

# Example of O(n) complexity

def linear_search(arr, target):

Instructor: Mr. Faith FAS 18


YEAR 10 CHRISTMAS TERM CODING NOTE

for i in range(len(arr)):

if arr[i] == target:

return i

return -1

Practical Class Task:

1. Write a Python program to implement linear search and analyze its time complexity.
2. Compare the time complexity of linear search (O(n)) with binary search (O(log n)).

Solution:

# Linear search (O(n))

def linear_search(arr, target):

for i in range(len(arr)):

if arr[i] == target:

return i

return -1

Individual Task:

Write a Python program to implement bubble sort and analyze its time complexity using Big-O Notation.

Assignment:

Write an essay on the importance of understanding algorithm efficiency, providing examples of real-world scenarios
where performance matters.

WEEK 11: Project Development

Learning Objectives:

• Learn how to plan and structure a programming project.


• Understand the stages of project development, from ideation to final implementation.
• Work in teams to develop a project based on a given specification.

Keywords:

Instructor: Mr. Faith FAS 19


YEAR 10 CHRISTMAS TERM CODING NOTE

• Project Development, Planning, Implementation, Testing, Deployment

Introduction:

Project development is a multi-step process that involves planning, designing, coding, testing, and deploying a
software solution. It requires teamwork, problem-solving, and technical skills.

Theory Contents:

1. Project Planning:
o Define the project scope, objectives, and deliverables.
o Create a timeline and allocate resources.
2. Project Design:
o Design the system architecture and user interface.
o Create a detailed plan for how the system will function.
3. Implementation:
o Write code to implement the project.
o Use version control tools (e.g., Git) to manage code changes.
4. Testing and Deployment:
o Test the system to ensure it meets requirements and functions correctly.
o Deploy the project to a live environment or share with users.

Practical Content:

Example:

• Project: Build a simple calculator in Python that can perform basic operations (addition, subtraction,
multiplication, division).
• Steps:
1. Plan the features and design the user interface.
2. Write Python code for each operation.
3. Test the calculator with various inputs.

Practical Class Task:

1. Start a new project with the goal of creating a basic inventory management system.
2. Plan the features and start designing the system.

Solution:

# Example of a basic calculator

def add(a, b):

return a + b

def subtract(a, b):

return a - b

def multiply(a, b):

Instructor: Mr. Faith FAS 20


YEAR 10 CHRISTMAS TERM CODING NOTE

return a * b

def divide(a, b):

if b != 0:

return a / b

else:

return "Division by zero is undefined"

Individual Task:

Work on your project idea, create a detailed project plan, and start implementing the code. Submit the project plan
as part of your assignment.

Assignment:

Write an essay explaining the different stages of project development, highlighting the challenges faced and how
they were overcome during the development of your project.

12. Project Testing and Debugging

Learning Objectives:

• Learn how to test a project to find and fix bugs.


• Understand different testing methodologies (unit testing, integration testing).
• Apply debugging techniques to fix errors in code.

Keywords:

• Testing, Debugging, Unit Testing, Integration Testing, Error Handling

Introduction:

Testing and debugging are critical steps in project development. Testing ensures that the project functions as
expected, while debugging helps identify and fix errors.

Theory Contents:

1. Types of Testing:
o Unit Testing: Testing individual components or functions.
o Integration Testing: Testing how different parts of the system work together.
2. Debugging Techniques:
o Use print statements or logging to track down errors.
o Use a debugger tool to step through code and find where it breaks.

Instructor: Mr. Faith FAS 21


YEAR 10 CHRISTMAS TERM CODING NOTE

3. Error Handling:
o Handle potential errors in your code to prevent crashes.
o Example: Using try-except blocks in Python.

Practical Content:

Example:

# Example of unit testing a function

def add(a, b):

return a + b

# Test the add function

assert add(2, 3) == 5, "Test failed"

Practical Class Task:

1. Write unit tests for the functions you created in your project.
2. Identify bugs in your project code and fix them.

Solution:

# Example of a test case

def test_add():

assert add(2, 3) == 5

assert add(-1, 1) == 0

Individual Task:

Write unit tests for your project functions and debug any issues you encounter. Submit the tests and a bug report.

Assignment:

Write an essay on the importance of testing and debugging in software development. Provide examples of common
bugs and how they can be fixed.

Instructor: Mr. Faith FAS 22

You might also like