2nd Term Assessment Revision Compt 8 (2) (Answer Key)
2nd Term Assessment Revision Compt 8 (2) (Answer Key)
TERM 2 – AY 2024-25
MID-TERM ASSESSMENT
REVIEW PACK 2
Name: Subject: C o m p u t e r
Date: Grade: 8th
Instructions:
➢ Read the questions carefully and answer them.
Question 1:
This is the code in your program which removes an atom name from the list.
def remove_atom_from_list(name):
if name in atoms:
atoms.remove(name)
print(name, "has been removed from the list.")
else:
print(name, "is not in the list.")
Question 2
a. Binary search
b. Linear search
1
TERM 2 AY 2024-25
A. The linear search method is usually slower compared to the binary search method,
but which one is faster depends on the characteristics of the data.
3. Which type of search algorithm uses a for loop? What commands go inside the for loop?
A. The linear search algorithm typically uses a for loop. This algorithm checks each
element of a list one by one to find the target value. Here’s how it works:
Comparison: Inside the loop, you compare the current element with the target value.
Action on Match: If the element matches the target, you take some action (e.g., print a
message or return the index).
Exit or Continue: If a match is found, you can exit the loop early, or continue checking
other elements if needed.
4. Describe the reasons why a programmer might choose to use procedures in their program.
A.
Programmers use procedures for several reasons:
1. Code Reusability: Write code once and reuse it, reducing redundancy.
2. Modularity: Breaks down large tasks into smaller, manageable pieces, making the code easier
to understand.
3. Easier Debugging: Isolate and test parts of the program separately, simplifying error
identification.
4. Abstraction: Hide complex details and provide clear interfaces for easier interaction.
5. Improved Collaboration: Allows team members to work on different parts of the code
simultaneously.
6. Efficiency: Reduces duplicated code and optimizes performance.
7. Scalability: Helps manage larger, more complex programs by keeping the structure organized.