05-introduction-to-python-arrays-and-lists.pptx

mentari58 0 views 23 slides May 19, 2025
Slide 1
Slide 1 of 23
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23

About This Presentation

lu


Slide Content

Introduction to Python Programming Part 5 : Arrays / Lists

How to use this resource Within each unit, you will learn how to develop and apply a range of Python programming skills. Skill explanations are in pink . After reading the explanation of a skill, apply it within the given tasks. The tasks are categorised into Rookie (Easy), Pro (Medium) or Beast (Hard). Once you have learned how to apply your new skills, demonstrate your ability by completing the given challenges. Don’t forget the debugging task! Once complete, review your performance! Skill Explanations: Pink Slides Tasks: Rookie Pro Beast Challenges: Rookie Pro Beast

Learning Objectives Rookie To be able to create a list. To be able to output a list. Pro To be able to edit and expand a pre-existing list. Beast To allow a user to input information into a list. To be able to conduct analysis on the information within a list.

Skill Contents Contents Confidence Level Writing an array / list Understanding the structure of an array / list Edit an array / list Once you complete a skill, colour code the box to show your level of confidence. You can always revisit the skill later on to boost your confidence. Key Colour Code I am very good at this skill and could show a friend how to do it. I am confident I can perform this skill on my own. I need to improve my understanding of this skill.

What is an Array? What is a List? As opposed to a variable which can only hold one item of data, an array can hold lots of data in a series of memory locations, each of which can hold a single item of data. All data in an array must be of the same data type, for example an array could hold a range of integers OR a range of string statements. However, in Python we use lists which can hold a range of different data types, for example, a list could contain a mixture of string and integer data.

Writing Python Arrays/ L ists In python, lists are used instead of arrays. To begin, a list is declared in the same way as a variable. The difference is after the equals symbol = you add square brackets [ ] and can add values within them, e.g. You can also store string statements in lists, e.g. In python it is possible to store different data types in a list, e.g.

Task 1: Rookie Pseudo code Python START numbers = [1,2,3,4,5,6,7,8,9,10] OUTPUT: numbers END Create a list to store the numbers 1 to 10. Output the list.

Task 1: Solution Add a print screen to show your coding here. Add a print screen to show your output solution here.

Task 2 : Rookie Pseudo code Python START names = [Gareth, Lionel, Zlatan, Rachel, Mia] OUTPUT: names END Create a list to store 5 names of your choice. Output the list.

Task 2 : Solution Add a print screen to show your coding here. Add a print screen to show your output solution here.

Understanding Array/List structures A list is structured as follows: Each box in the list can contain a data item. The individual boxes in the array can be used just like variables . Each box has a numerical reference called an index that is used to refer to the individual data item. Note that in Python the first element of the list shown here has an index of zero . So in the above example, index 0 stores the number 2, index 6 stores the number 14, etc. Index 1 2 3 4 5 6 7 8 9 10 11 List Data 2 4 6 8 10 12 14 16 18 20 22 24

Task 3: Understanding index List Command Output O utput a specific value of a list by using this command: Read the following lists. Using your understanding of list indexing, identify the correct data to be output if the following commands were written;

How to edit a list Lists hold variable information, therefore the data stored can be changed. See the table below which shows some of the common ways of editing your array: Method of editing Programming Command Assign a value to an existing index Allow a user to input a value Print the length of a list Add another value to the end of an existing list Remove an indexed value Find an index number

Task 4: Editing a list Create the following list in python: Perform the editing techniques shown on the previous slide on the list and print screen the output. Method of editing Output Assign a value to an existing index Allow a user to input a value Print the length of a list Add another value to the end of an existing list Remove an indexed value Find an index number

Programming Challenges Now you have learned some programming skills, it’s time to put them into practice! Complete the following programming challenges. Start with the Rookie challenge and see how far you can push yourself. Finally, complete the debugging challenge . Once you have finished your challenges, complete the review . Look back at the skills you have learned so far to help you solve the challenge.

Programming Challenge: Rookie Store the following information within a list then print it out; 1,2,3,4,5,6,7,8,9,A,B,C,D,E,F Add a print screen of your solutions to the next slide. 1 Mark

Programming Challenge: Rookie - Answer Add a print screen to show your coding here. Add a print screen to show your output solution here.

Programming Challenge: Pro Create a list which includes all the days of the week (Monday to Friday) Append the days Saturday and Sunday to the end of your list. Print out your final list. Add a print screen of your solutions to the next slide. 1 Mark

Programming Challenge: Pro - Answer Add a print screen to show your coding here. Add a print screen to show your output solution here.

Programming Challenge: Beast Ask a user to input 5 numbers and store each of them in a list. Ask the user to remove one of the inputted values. Output the following information within suitable sentences; All the data stored in the list The length of the list The total value of the list Add a print screen of your solutions to the next slide. 1 Mark

Programming Challenge: Beast - Answer Add a print screen to show your coding here. Add a print screen to show your output solution here.

Debugging Question The following information needs to be put into a list: Bananas, Apples, Oranges, Prunes, Grapes, Strawberries, Plumbs Which list below will store the items correctly: 1 Mark

Challenges Review Challenge Your Score (Max 1 mark each) Rookie Challenge Pro Challenge Beast Challenge Debugging Challenge Unit Review What Went Well: Even Better If: Complete the table below to help you identify what areas you are confident at and which areas you need to improve further: