PROGRAMMING: ATOM FINDER
Learning Objectives
• Understanding how to store and use blocks of code (procedures) in
programs.
• Creating a procedure to find an element in a list.
• Comparing different search algorithms for finding an element in a list.
Activity Overview
Students will write a Python program to:
✓ Add and remove atoms from a list.
✓ Search for an atom within the list.
Unplugged Activity: Atom Search Game
• Students at City Park School played an "atom search" game.
• They wrote atom names on separate cards, shuffled them, and
placed them face down.
• Atoms were not arranged in order.
List of atoms used in the game: Hydrogen, Helium, Carbon, Nitrogen, Oxygen,
Fluorine, Neon, Sodium, Magnesium, Aluminium, Silicon, Phosphorus, Sulfur,
Chlorine, Argon, Potassium, Calcium, Iron, Cobalt, Nickel, Copper, Zinc, Silver,
Tin, Antimony, Iodine, Platinum, Gold, Mercury, Lead.
Game Rules
• Players search for a specific atom name by flipping one card at a
time.
• If the card does not match the target atom, it is placed back face
down.
• Players continue flipping cards until they find the correct atom.
Example:
✓ Tasha challenged Jasmin to find "Gold."
✓ Jasmin flipped one card at a time until she found "Gold."
Computational Thinking Concepts
✓ Linear Search: The process of flipping one card at a time is an
example of a linear search, where each item is checked
sequentially until the target is found.
✓ Sorting: The atoms were not in order, making searching more
difficult.
✓ Understanding how search algorithms work can improve efficiency
when looking for data in a computer program.
Did You Know?
• Scientists use computers to study both very small (atoms, subatomic
particles) and very large (galaxies) structures.
✓ A powerful supercomputer called Stampede was used to simulate a
galaxy formation.
Discussion Points
✓ How can computers help in learning different subjects?
✓ Why is it important to use computers for storing and processing
scientific data?
Important Terms
✓ Module – A reusable section of code.
✓ Function – A block of code designed to perform a specific task.
✓ Procedure – A set of instructions in programming.
✓ Search Term – The item being searched for in a list.
✓ Linear Search – A method where elements are checked one by
one.
✓ Binary Search – A more efficient search method (works on sorted
lists).
✓ Parameter – A value passed into a function or procedure.
AMEND A PROGRAM
Lesson Objectives
In this lesson, you will learn:
✓ How to adapt a program.
✓ Understanding that program structures have a header and a body.
Spiral Back
✓ Previously, you learned how to write programs in Python.
✓ You used loops and control structures (such as if statements).
✓ This lesson will help you develop these skills further by adapting a
Python program.
Atom List Program
• In Unit 3, you made a Team Manager program with a menu that
allowed adding and deleting team members.
• This unit uses a similar program called Atom List.
• The Atom List program manages atomic elements from Hydrogen to
Radon.
• A prepared version of this program is available from the teacher.
Understanding the Program Code
• Open the Atom List program and read through the code.
• The program is divided into three sections:
i. List of atoms (stores atomic elements)
ii. Procedure definitions (functions that handle operations)
iii. Main program (displays the menu and executes user choices)
List of Atoms
• The first section stores atomic elements in a list called atoms.
• The list contains 88 elements.
Procedure Definitions
• This part of the program contains functions that define how operations
(adding/removing items) are performed.
• More procedure definitions will be introduced in the next lesson.
Main Program
• The final part is the main program.
• It:
✓ Displays the menu.
✓ Processes user input.
✓ Calls relevant procedures/functions.
Features of the Code
The code for adding an atom to the list,
if choice == "A":
name = input("Enter the name of an atom to add: ")
[Link](name)
print(name, "has been added to the list")
• Uses input() to take user input.
• Uses .append(name) to add the atom to the list.
The code for removing an atom from the list,
if choice == "R":
name = input("Enter the name of an atom to remove: ")
[Link](name)
print(name, "has been removed from the list")
✓ Uses input() to take user input.
✓ Uses .remove(name) to delete the atom from the list.
Running the Program
Run the program to see the menu interface.
The menu allows the user to:
✓ View the list of atoms.
✓ Add an atom.
✓ Remove an atom.
✓ Print the full list.
✓ Exit the program.
Menu Options
Option Function
A Append an atom to the list
R Remove an atom from the list
P Print the entire list
X Exit the program
Example:
• If you type "A", the program will ask for an atom name and
add it to the list.
• If you type "R", it will ask for an atom name and remove it.
• If you type "P", it will print the entire list.
• If you type "X", the program exits.
Activity: Modifying the Program
• Copy the Atom List program onto your computer.
• Open the program and read the three sections.
• Run the program.
• Modify the program:
-Add "Uranium" to the list.
-Delete "Iron" from the list.
-Print the updated list.
Understanding Program Structure
Header and Body
The Atom List program uses if structures.
An if structure consists of:
✓ Header – Specifies the condition.
✓ Body – Contains indented commands executed when the
condition is met.
Example of a Header
if choice == "A":
-Ends with a colon (:).
-Controls what happens inside the body.
Example of a Body,
name = input("Enter the name of an atom to add: ")
[Link](name)
print(name, "has been added to the list")
✓ Indented under the if statement.
✓ Executes only if the condition (choice == "A") is met.
Loop Structures in the Program
• The Atom List program contains a loop.
• A loop:
▪ Has a header that controls how many times it runs.
▪ Has a body that contains repeating commands.
Types of Loops
The loop in this program can be:
✓ For loop – Iterates a fixed number of times.
✓ While loop – Runs until a condition is met.
Example of a While Loop
while choice != "X":
-Runs the menu continuously until the user types "X".
Nested Structures and Double Indentation
• This program has nested structures.
• A nested structure is when one structure is inside another.
• Uses double indentation for clarity.
Example of Double Indentation
while choice != "X":
if choice == "A":
name = input("Enter the name of an atom to add: ")
[Link](name)
print(name, "has been added to the list")
✓ The while loop controls the entire menu system.
✓ The if statement is inside the loop and follows double indentation.
Summary of what you have learnt
✓ The Atom List program allows managing a list of atomic elements.
✓ It consists of:
• A list of atoms.
• Procedure definitions for adding/removing atoms.
• A main program that displays a menu and executes user
actions.
✓ Key programming concepts:
• Headers and bodies (used in if statements and loops).
• Loop structures (while loop keeps the menu running).
• Double indentation (used for nested structures).
✓ The activity involves modifying the program by adding, deleting,
and printing elements.