Presentation is loading. Please wait.

Presentation is loading. Please wait.

Starter You have been asked to write a program to store the names of everybody in a class. Assuming there are 20 pupils in the class, how would you do.

Similar presentations


Presentation on theme: "Starter You have been asked to write a program to store the names of everybody in a class. Assuming there are 20 pupils in the class, how would you do."— Presentation transcript:

1 Starter You have been asked to write a program to store the names of everybody in a class. Assuming there are 20 pupils in the class, how would you do this?

2 Lists & Arrays Python

3 Objectives 2.3.2 Understand the need for and be able to select and use data structures one-dimensional arrays two-dimensional arrays

4 What are Arrays? If we think of variables as a box. Arrays are a collection of boxes. Array - list of homogeneous items Each “box” has an address starting at 0. We call the address it’s INDEX [0] ‘Alf’ [1] ‘Betsy’ [2] ‘Charlie’ [3] ‘David’

5 Printing Lists Individual elements may be printed by using the name of the list and then the index of the element you wish to print in square [] brackets. Think: What programming construct could you use to print out every element in a list?

6 Activity 1. Complete Activity 1 the VLE.

7 More than one dimension?
We were working with 1 Dimensional Arrays. These are effectively lists. What about if we had lists….of lists??? [0] [1] [2] [3] [4] What Value is at Scores[1][2]? Jimmy 12 15 17 19 Joanna 9 16 18 20 Jess 5 6 7 John 4 [0] 16 [1] [2] [3]

8 Activity 1. Complete Activity 2 the VLE.

9 To store related information
Week 2 - Recap What is the purpose of a list? How do you create a list? Add an element? Remove a element? To store related information scores = [35, 62, 98, 54, 21] scores.append(71) scores.pop(2) Teacher note: Random numbers

10 Plenary If variables are like boxes, what are lists?
What methods can we use to add and remove elements to/from a list? What is a list element?


Download ppt "Starter You have been asked to write a program to store the names of everybody in a class. Assuming there are 20 pupils in the class, how would you do."

Similar presentations


Ads by Google