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

Lesson 11 Arrays Lists

Uploaded by

cguy7811
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Lesson 11 Arrays Lists

Uploaded by

cguy7811
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 23

LO: Critically evaluate and apply lists in Python to solve complex problems, demonstrating the ability to create efficient,

scalable code.

Recall Realise what you have done previously

for i in range (0,3): for i in range(1, 10, 2): for i in range(2): ACP
print (i) print(i) for j in range(3): Check

print(i, j)
Question: What will Question: What will Question: What will
this code output? this code output? this code output?
count = 1 x=0 for i in range(5):
while count < 4: while x < 5: if i % 2 == 0:
print(count) print("Looping!") print(i) VAA
Check
count += 1
Question: What will # Add missing line to Question: What will
this code output? avoid an infinite loop this code output?

Success Criteria
Write simple Python programs that use lists to store and display information
Compare and contrast different ways to manipulate lists (e.g., using .sort() vs. sorted()).
Design and implement Python programs that solve complex problems using lists
LO: Critically evaluate and apply lists in Python to solve complex problems, demonstrating the ability to create efficient, scalable code.
for i in range (0,3):10 minutes
for i in range(1, 10, 2):Realisefor
whati you
in range(2):
printRecall
have done previously
(i) print(i) for j in range(3):
print(i, j)
0, 1, 2 1, 3, 5, 7, 9 i=0,j=0 ACP
Check
i=0,j=1
i=0,j=2
i=1,j=0
i=1,j=1
i=1,j=2
VAA
Check

count = 1 x=0 for i in range(5):


while count < 4: while x < 5: if i % 2 == 0:
print(count) print("Looping!") print(i)
count += 1
1, 2, 3,
Success Criteria
x=x+1 0, 2, 4
Write simple Python programs that use lists to store and display information
Compare and contrast different ways to manipulate lists (e.g., using .sort() vs. sorted()).
Design and implement Python programs that solve complex problems using lists
LO: Critically evaluate and apply lists in Python to solve complex problems, demonstrating the ability to create efficient, scalable code.

Arrays / Lists
ACP
Check

Learning objective: Critically evaluate and apply lists in Python to solve


complex problems, demonstrating the ability to create efficient, scalable
code.

Success Criteria
• Write simple Python programs that use lists to store and display VAA
information (e.g., grocery list, favorite movies). Check

• Compare and contrast different ways to manipulate lists (e.g.,


using .sort() vs. sorted()).
• Design and implement Python programs that solve complex problems
using lists (e.g., creating a movie database or a to-do list application).
Today,Criteria
Success we will be practicing the VAA of being agile by the ability to be: curious, be
willing
Write to Python
simple work alone,
programsbe proactive,
that keenand
use lists to store to display
learn,information
show enterprise think
independently
Compare . different ways to manipulate lists (e.g., using .sort() vs. sorted()).
and contrast
Design and implement Python programs that solve complex problems using lists
LO: Critically evaluate and apply lists in Python to solve complex problems, demonstrating the ability to create efficient, scalable code.
Connection finding to new learning

Understanding Lists in Python


ACP
Check

• What is a List?
• A list in Python is a collection of related items stored together in
a single variable.

VAA
Check

Think Pair Share: Can you think of other examples where you have a collection
of related items? Share your ideas!”
Success Criteria
Write simple Python programs that use lists to store and display information
Compare and contrast different ways to manipulate lists (e.g., using .sort() vs. sorted()).
Design and implement Python programs that solve complex problems using lists
LO: Critically evaluate and apply lists in Python to solve complex problems, demonstrating the ability to create efficient, scalable code.
Connection finding to new learning

Basic Syntax for Lists in Python


ACP
Check

In Python, lists are created using square brackets [ ]. Each item is


separated by a comma.
class_students=[“Aleena”, Rodina”, “Youssef”]

Each item in a list is called an element. Elements can be any data VAA
type, like strings, numbers, or even other lists Check

[0] [1] [2]What do you think


How would I print colours = ["red", "blue", "green"] would happen if we
only blue? try access an index
print(colours)
that does not exist
Success Criteria Mystery list demo
Write simple Python programs that use lists to store and display information
Compare and contrast different ways to manipulate lists (e.g., using .sort() vs. sorted()).
Design and implement Python programs that solve complex problems using lists
LO: Critically evaluate and apply lists in Python to solve complex problems, demonstrating the ability to create efficient, scalable code.
Critically Thinking

How much do you know?


ACP
● What does the program do? Check

myList = [23, 18, 1, 34, 2, 42]

search = int(input(“What are you looking for?”))

for i in range(5): VAA


if search == myList[i]: Check

print(“Found!”)
Challenge: How could we change this program so that it
automatically adjusts if we add more items to the list?
Success Criteria
Write simple Python programs that use lists to store and display information
Compare and contrast different ways to manipulate lists (e.g., using .sort() vs. sorted()).
Design and implement Python programs that solve complex problems using lists
LO: Critically evaluate and apply lists in Python to solve complex problems, demonstrating the ability to create efficient, scalable code.
Critically Thinking

Paired task - whiteboards


ACP
Check

• Create a list of your three favourite foods and show the following:

• Print the entire list.


VAA
Check
• Print each element individually using its index

• Discussion: What item do you think would be the most popular


in this class based on your list.
Success Criteria
Write simple Python programs that use lists to store and display information
Compare and contrast different ways to manipulate lists (e.g., using .sort() vs. sorted()).
Design and implement Python programs that solve complex problems using lists
LO: Critically evaluate and apply lists in Python to solve complex problems, demonstrating
Watchthe ability to create
this video to efficient,
know about scalable code.
declaration of list in python

How to declare a List in Python


ACP
Check

• VariableName = [] #This would make an empty list

• VariableName = [1,2,3,4] #This would make a list of numbers

• VariableName = [“Discovery School”, “Newcastle College”, VAA

“Newcastle University”] #This would make a list of strings. Check

Success Criteria
Write simple Python programs that use lists to store and display information
Compare and contrast different ways to manipulate lists (e.g., using .sort() vs. sorted()).
Design and implement Python programs that solve complex problems using lists
LO: Critically evaluate and apply lists in Python to solve complex problems, demonstrating the ability to create efficient, scalable code.
Hard working time

Activity 1 – Indexing
ACP
Check

Activity1: Favourite Movies List


Create a list called favourite_movies with five of your favourite
movies.
Print the entire list to see all your favourite movies.
Print just the first and last movie in the list by using their positions VAA
(index). Check
Support: Challenge:
.append() method
Hint: Remember, and
lists start print
counting the updated
from list.
Can you print the second-to-last movie in
0, so the first movie is at the list using negative indexing?
favourite_movies[0] and the last movie Add one more movie to your list using the
can be accessed with favourite_movies[- .append() method and print the updated
1]. See slide 11 list.
Success Criteria
Write simple Python programs that use lists to store and display information
Compare and contrast different ways to manipulate lists (e.g., using .sort() vs. sorted()).
Design and implement Python programs that solve complex problems using lists
LO: Critically evaluate and apply lists in Python to solve complex problems, demonstrating the ability to create efficient, scalable code.

Support

Support
ACP
Check

VAA
Check

Success Criteria
Write simple Python programs that use lists to store and display information
Compare and contrast different ways to manipulate lists (e.g., using .sort() vs. sorted()).
Design and implement Python programs that solve complex problems using lists
LO: Critically evaluate and apply lists in Python to solve complex problems, demonstrating the ability to create efficient, scalable code.
Hard working time

Activity 2 - Grocery List Sorting


ACP
Check

• Create a list called grocery_list with six items you need to buy
from the store (e.g., ["milk", "bread", "eggs", "apples", "carrots",
"pasta"]).
• Print the list in its original order.
• Use the .sort() method to sort the list alphabetically, then print it
again. VAA
Check

• Sort the list in reverse alphabetical order and print it.


Challenge:
Support Before sorting, make a copy of the original list. Try using
grocery_list.sort() sorted(grocery_list) to create a sorted version without
Grocery_list.sort(reverse=True) changing the original list.
See slide 11 How many items in grocery_list start with the letter "a"? Use
Success Criteria a loop to count them after sorting.
Write simple Python programs that use lists to store and display information
Compare and contrast different ways to manipulate lists (e.g., using .sort() vs. sorted()).
Design and implement Python programs that solve complex problems using lists
LO: Critically evaluate and apply lists in Python to solve complex problems, demonstrating the ability to create efficient, scalable code.
Hard working time

Activity 3
Hint: Use len(arr) function to find ACP
a) Write a Python program to find the sum Check
the number of items in the list.\
of all the items in the list
Support See slide 11
• Sample Output
[20, 75, 33, 90, 11, 56, 87] Challenge a: Find the average of the
items in the list and display it
Sum of items is 372 alongside the sum.

Write code to find the sum only of VAA


the even numbers in the list. Check
b) Write a Python program to find the
largest number in a list Challenge b: Find the smallest
• Sample Output number in the list as well, and display
both the largest and smallest values.
[82,4,56,78,4,34,5,100,9] Find the second-largest number in
Largest Number : 100 the list.
Success Criteria
Write simple Python programs that use lists to store and display information
Compare and contrast different ways to manipulate lists (e.g., using .sort() vs. sorted()).
Design and implement Python programs that solve complex problems using lists
LO: Critically evaluate and apply lists in Python to solve complex problems, demonstrating the ability to create efficient, scalable code.

Activity 3- Solutions
ACP
Check

a) b)

VAA
Check

Success Criteria
Write simple Python programs that use lists to store and display information
Compare and contrast different ways to manipulate lists (e.g., using .sort() vs. sorted()).
Design and implement Python programs that solve complex problems using lists
LO: Critically evaluate and apply lists in Python to solve complex problems, demonstrating the ability to create efficient, scalable code.
Hard working time
Challenge: The Guest List Loop
ACP
Check

• Create a list called guest_list with the names of five friends


you would invite to a party.
• Write a for loop that goes through each name in guest_list and
prints a personalised invitation, such as
• Hello Max, you’re invited to my party!
VAA
Check
Ask the user if they’d like to add another guest.
Support
If they say yes, prompt them to enter a name,
for guest in guest_list:
add it to guest_list, and print the updated
print(f”Hello {guest}, you’re invited to the party!”)
list.After printing all the invitations, print the
total number of guests invited to the party

Success Criteria
Write simple Python programs that use lists to store and display information
Compare and contrast different ways to manipulate lists (e.g., using .sort() vs. sorted()).
Design and implement Python programs that solve complex problems using lists
LO: Critically evaluate and apply lists in Python to solve complex problems, demonstrating the ability to create efficient, scalable code.

Plenary
ACP
Check
Two Stars:
Think of two things that went well today. This can be:
Something you learned and understood well.
A task or concept that you felt confident about.

A Wish:
VAA
Think of one thing you want to improve or learn more about. Check

This could be:


Something you found difficult or need more practice with.
A concept or task you’d like to revisit in the future.

Success Criteria
Write simple Python programs that use lists to store and display information
Compare and contrast different ways to manipulate lists (e.g., using .sort() vs. sorted()).
Design and implement Python programs that solve complex problems using lists
LO: Critically evaluate and apply lists in Python to solve complex problems, demonstrating the ability to create efficient, scalable code.

Recap- Random Library(module)


ACP
Random module is used to generate random numbers and data in Check

Python.
To use all the functions under this library, you have to import the library
using

VAA
Check

Success Criteria
Write simple Python programs that use lists to store and display information
Compare and contrast different ways to manipulate lists (e.g., using .sort() vs. sorted()).
Design and implement Python programs that solve complex problems using lists
LO: Critically evaluate and apply lists in Python to solve complex problems, demonstrating the ability to create efficient, scalable code.

Exam Question
ACP
Check

VAA
Check

Answer:
Success Criteria
Write simple Python programs that use lists to store and display information
Compare and contrast different ways to manipulate lists (e.g., using .sort() vs. sorted()).
Design and implement Python programs that solve complex problems using lists
LO: Critically evaluate and apply lists in Python to solve complex problems, demonstrating the ability to create efficient, scalable code.

Searching algorithms
ACP
Check

• This year we will learn about two search algorithms:


1. Linear search
2. Binary search
• When searching for a particular item through unsorted data, the
only sensible option is to start at the beginning and look at every VAA
item until you find the one you want. Check

• This is what a Linear search algorithm does.

Success Criteria
Write simple Python programs that use lists to store and display information
Compare and contrast different ways to manipulate lists (e.g., using .sort() vs. sorted()).
Design and implement Python programs that solve complex problems using lists
LO: Critically evaluate and apply lists in Python to solve complex problems, demonstrating the ability to create efficient, scalable code.

Next lesson
ACP
Check

VAA
Check

Success Criteria
Write simple Python programs that use lists to store and display information
Compare and contrast different ways to manipulate lists (e.g., using .sort() vs. sorted()).
Design and implement Python programs that solve complex problems using lists
LO: Critically evaluate and apply lists in Python to solve complex problems, demonstrating the ability to create efficient, scalable code.

Activity 5 START ACP


array  [insert array Check

• Create a list having below animals: items here]


• Cat, dog, parrot, lion, tiger, bear, chicken item  user input
match  FALSE
• Ask the user which animal they want to find FOR count  1 TO LEN
• Hint: Use the pseudocode to create the program (array)
IF item = array
• Challenge: Rewrite this program using a while [count] VAA
loop and subroutine  match  Check

linearSearch(myItem,myList) TRUE
ELSE
END IF
END FOR
OUTPUT: match
Success Criteria END
Write simple Python programs that use lists to store and display information
Compare and contrast different ways to manipulate lists (e.g., using .sort() vs. sorted()).
Design and implement Python programs that solve complex problems using lists
LO: Critically evaluate and apply lists in Python to solve complex problems, demonstrating the ability to create efficient, scalable code.

Lists with other Lists


ACP
Check

• What will the output of this program be?

pupils = [“Doug”, “Alex”, “Martin”, “Steve”]


marks = [99,67,34,75]
print(pupils[0], “ mark in the test was “,marks[0])
print(pupils[1], “ mark in the test was “,marks[1]) VAA
Check
print(pupils[2], “ mark in the test was “,marks[2])
print(pupils[3], “ mark in the test was “,marks[3])

Success Criteria
Write simple Python programs that use lists to store and display information
Compare and contrast different ways to manipulate lists (e.g., using .sort() vs. sorted()).
Design and implement Python programs that solve complex problems using lists
LO: Critically evaluate and apply lists in Python to solve complex problems, demonstrating the ability to create efficient, scalable code.

Activity 6 – Capital Cities


ACP
Check

• Write a program that stores the names of five countries and their
capital cities in two different lists. The program should print the name of
the country and its capital city for all five countries.

• Challenge:
Write a Python program to find common items from two lists VAA
Check
• Sample Output
[23,45,67,78,89,34]
[34,89,55,56,39,67]
Common items from two lists : {89, 34, 67}
Success Criteria
Write simple Python programs that use lists to store and display information
Compare and contrast different ways to manipulate lists (e.g., using .sort() vs. sorted()).
Design and implement Python programs that solve complex problems using lists
LO: Critically evaluate and apply lists in Python to solve complex problems, demonstrating the ability to create efficient, scalable code.

Plenary
ACP
Check

Two Stars and a Wish


• Write down two things that went well. Did you get a good score
on a quiz? Or complete an activity before the deadline?

• Write a wish about what you want to achieve in the next lesson VAA
Check
or Is there anything you need me to go over again?

Success Criteria
Write simple Python programs that use lists to store and display information
Compare and contrast different ways to manipulate lists (e.g., using .sort() vs. sorted()).
Design and implement Python programs that solve complex problems using lists

You might also like