Year 10 Coding Note
Year 10 Coding Note
Objectives Keywords:
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.
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:
WEEK TWO
Objectives: Keywords:
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:
Example:
for i in range(5):
print(f"Iteration {i + 1}")
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.
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.
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.
WEEK THREE
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
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.
python
Copy code
# Function to calculate the area of a rectangle
def calculate_area(width, height):
return width * height
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:
Learning Objectives:
Keywords:
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.append(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:
print(my_tuple[0]) # Output: 1
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:
# Accessing elements
print(my_list[0]) # Output: 1
print(my_tuple[0]) # Output: 1
my_list[0] = "orange"
Solution:
fruits_list.append("fig")
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.
Learning Objectives:
Keywords:
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:
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}
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
# Accessing values
print(student["age"]) # Output: 21
# Creating a set
numbers = {1, 2, 2, 3, 4}
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 = {
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.
Learning Objectives:
Keywords:
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:
Example:
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.close()
content = file.read()
file.close()
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.close()
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.
Learning Objectives:
Keywords:
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.
3. Boil water.
4. Add tea leaves to the boiling water.
5. Pour the water into a cup.
Example of pseudocode:
START
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:
if a > b:
return a
else:
return b
print(result) # Output: 20
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:
if a > b:
return a
else:
return b
# Example usage
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.
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:
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.
class Node:
self.value = value
self.left = None
self.right = None
root = Node(1)
root.left = Node(2)
root.right = Node(3)
Practical Content:
Example:
# Implementing a stack
stack = []
stack.append("book1")
stack.append("book2")
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.
Assignment:
Write an essay on the use of complex data structures in real-world applications, providing examples for each.
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:
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.
Practical Content:
Example:
for i in range(len(arr)):
if arr[i] == target:
return i
return -1
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:
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.
Learning Objectives:
Keywords:
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.
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:
return a + b
return a - b
return a * b
if b != 0:
return a / b
else:
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.
Learning Objectives:
Keywords:
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.
3. Error Handling:
o Handle potential errors in your code to prevent crashes.
o Example: Using try-except blocks in Python.
Practical Content:
Example:
return a + b
1. Write unit tests for the functions you created in your project.
2. Identify bugs in your project code and fix them.
Solution:
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.