Grade 7 Lesson 1 Week 1 (Python Programming List and Array)
Grade 7 Lesson 1 Week 1 (Python Programming List and Array)
Grade 7
TABLE OF
CONTENTS
01 OBJECTIVES 04 OBJECTIVE
02 INTRODCUT 05 MATERIALS
ION
03 PROGRAMM
ING
Lesson 1 – Programming: Lists and Arrays
01 Objectives
By the end of the lesson you will understand more
about:
ION
Data structures are ways to organize and store data so
that it can be accessed and modified efficiently.
Types :
1.Linear Data Structures: Data elements are arranged sequentially. Example: Arrays, Linked Lists.
2.Non-Linear Data Structures: Data elements are arranged in a hierarchical manner. Example:
Trees, Graphs.
Arrays:
Ice Cube Tra
03
Book Shelf
Cinema Seats
CHOOSING BETWEEN
Personal Task Manager
LIST OR ARRAY
Recipe Book
YOUR
Game Scoreboard
• You're working with large amounts of numerical data
• You need to perform many mathematical operations
• These functions have to be defined alongside the main body of the code.
• As well as user defined functions and modules, programming software also contains pre-written libraries of methods
that can be called and used without the developer having to write anything.
• In this lesson you will learn about new data types called lists and arrays and then use pre-written methods to carry
out the actions on the list and array variables.
continued
A list method is linked to the list object, a string method is linked to a string object and so on.
Consider the string variable type you have previously studied. A string is a list or sequence of characters (Char).
In order to access the data in a list or an array, you need to access the individual elements. Each element is in a
separate location inside the variable.
In the example below, the term HELLOWORLD has been stored in a variable called MyWord.
Each character is in its own element, represented here by the numbers below the characters.
Notice that the first element is element 0, not element 1. This is always the case with a list or an array.
ACTIVITY 01-
There are two ways to declare an array or a list. The first is:
continued
MyWord = [10] The number in the brackets identifies the number of elements in the variable.
The number of elements has been fixed; this makes it an Array. The variable
is
identified as ‘static’ because it cannot grow or shrink.
MyWord = [ ] If there is no number in the brackets, the size of the variable is not set.
This means it can grow or shrink. You might begin by inputting 3 values,
giving it a size of 3. If you add another 5, the variable now has a size of
8. Deleting 2 values reduces the variable size to 6. This time the
variable is identified as dynamic i.e. it can be changed. This makes it a
List.
ACTIVITY 01-
Values can be inserted into a list or declared at the beginning
of the program. In this program we will input the values at the
continued
# display, sort and reverse a list of numbers
beginning.
Numbers = [6, 49, 33, 8, 72, 1060, 198] The numbers are
put onto the list
Numbers = [6, 49, 33, 8, 72, 1060, 198] counter = 0
print ('\n\nEnd')
ACTIVITY 01-
The code below uses lists and allows users to input 10 numbers; it then outputs the numbers onto
continued
the screen.
# list example
• Static – fixed
NAE
Thank
you