0% found this document useful (0 votes)
5 views

Grade 7 Lesson 1 Week 1 (Python Programming List and Array)

Uploaded by

Saqib Tipo
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Grade 7 Lesson 1 Week 1 (Python Programming List and Array)

Uploaded by

Saqib Tipo
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 22

Lesson 1

Programming List and


Arrays

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:

• Lists and Array


02
INTRODUCT
What are Data Structures?

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

The organized Box


• An array is like a row of boxes
• Each box has a number (index) and can hold one piece of data
• All boxes are the same size and right next to each other
• Example: A row of lockers in school Row of lockers

• How would you describe an array to a friend using everyday objects?


Parking Lot
03 Arrays:
Advantage
s
• Quick access to any element using its index
• Good for storing and accessing data in a specific order
• Efficient for iterating through all elements
• Works well when you know the size of your data in advance
• Can you think of a situation where quick access to data would be
important?
03 Arrays:
Dis
Advantages
• Fixed size - hard to add more elements if it gets full
• Inserting or deleting elements in the middle is slow
• Wastes space if not all elements are used
• What might happen if you tried to add more items to a full array?
Linked List :
04
(The Chain of data)
• A linked list is like a chain of paper clips
• Each clip (node) holds a piece of data and a link to the next clip
• Nodes can be scattered in memory, unlike arrays
• Example: A scavenger hunt where each clue points to the next
• How is a linked list different from an array based on this description?
The parts of
Linked List
NODE DATA NEXT HEAD TAIL
A pointer to next node Points to first node The last node (points
The basic unit of a linked list The part which stores
. information to null)
Linked List :
04
Advantages

• Easy to add or remove elements


• Can grow or shrink as needed
• Efficient use of memory - only uses what it needs
• Good for when the size of your data might change often
• In what situations might a linked list be better than an array?
Linked List :
04
Disadvantages
• Slower to access individual elements - must traverse the list
• Uses more memory than arrays (needs to store the 'next' pointer)
• Not as efficient for iterating through all elements
• Can you think of a task that might be harder with a linked list than an array?
Projects Using Lists

CHOOSING BETWEEN
Personal Task Manager

LIST OR ARRAY
Recipe Book

Contact Management System

• Use lists when: Projects Using Arrays

• You need to store different types of data


• You're working with smaller amounts of data
• You need flexibility in adding/removing items
Image Processing
Weather Forecasting App
• Use arrays when:

YOUR
Game Scoreboard
• You're working with large amounts of numerical data
• You need to perform many mathematical operations

• Can you think of a project where NAME


you'd use lists? What
about arrays?
ACTIVITY 01
• You have looked at modules and functions in programming. Ask your teacher if you need a quick reminder what these
are.

• These functions have to be defined alongside the main body of the code.

• They are referred to as user defined functions or user defined modules.

• 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.

• The pre-written code is called a function.


ACTIVITY 01-
Methods link to actions taken on the object they are linked to.

continued
A list method is linked to the list object, a string method is linked to a string object and so on.

Functions exist on their own.

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\nThe numbers are:\n') The list is displayed


while (counter <7): one element at a time
print (Numbers[counter], end=" ") using the counter to
counter+=1 locate the position
Notice that the code to sort and reverse the list is actually Numbers.sort()
very short.
Numbers.sort() counter = 0
The list method
Numbers.reverse() print ('\n\nSorted - the numbers are:\n') called sort is used
while (counter <7): and the sorted list
print (Numbers[counter], end=" ") is output
The variable is ‘Numbers’. counter+=1
The methods called are ‘Sort’ and ‘Reverse’.
Numbers.reverse()
The brackets are part of the call method.
counter = 0
The method called
print ('\n\nReversed - the numbers are:\n') reverse is used and
while (counter <7): the reversed list is
print (Numbers[counter], end=" ") output
counter+=1

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

The list is declared and without a


MyNumbers = [] value inside it is dynamic
Only the counter controlling the loop
counter = 0 limits the number of numbers input

while (counter <10): Input the code into


MyNumbers.insert (counter, input('Input Number\n')) Python and execute it.
counter+=1
counter = 0 Modify the code to
‘sort and print’ and
print ('Outputs are: ') ‘reverse and print’ the
Python automatically adds a numbers.
new line at the end of an output
while (counter <10): You can add another new line by
print (MyNumbers[counter], end=" ") adding \n or you can stop a new
counter+=1 line by adding end =" "
which means that the numbers
output will all appear on the
print ('\nEnd!'); same line
WRAPPING UP-
LIST AND ARRAYS IN REAL WORLD
• Lists and arrays are used everywhere in programming
• Examples:
• To-do lists in productivity apps
• Playlists in music streaming services
• Inventory systems in online stores
• Data analysis in scientific research
• Can you think of any apps or games you use that might use lists or arrays?
• What was the most interesting thing you learned today about lists and arrays?
05 Teminologies
• Brackets/Parentheses - round or square brackets that
encase sections of code. Brackets should always be both
opened and closed otherwise there will be an error at
execution

• Dynamic - able to change. A dynamic list can grow or shrink


depending on the number of values inside it

• Static – fixed

• Compiler - a computer program that transforms source


code into a different programming language
“Arrays are like rows of boxes, each box
having a number that lets you access
the data inside quickly and easily.”

“In programming, lists are like shopping carts:


hey grow and shrink as you add or remove items
As a teacher, I appreciate how the Programming: Lists and Arrays effectively introduces Grade 7 students to the concept of List
and arrays in Python. The lesson's combination of simple explanations, relatable examples, and interactive activities made the
topic accessible and engaging. My students were excited to create their own programs in python to explore list and arrays. This
lesson not only educated them about Programming in python but also make their attentions in everyday life where list and arrays
are used and how they can be reflected in programming too.."

YOUR Mr Saqib Riaz


ICT Teacher / Computer Science Lecturer

NAE
Thank
you

You might also like