Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
18 views

05 - Introduction To Python - Arrays and Lists

This document provides an introduction to using arrays and lists in Python programming. It explains what arrays and lists are, how to create and output lists, edit existing lists, and allow user input into lists. Example tasks and challenges are provided to help learners practice applying these list skills.

Uploaded by

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

05 - Introduction To Python - Arrays and Lists

This document provides an introduction to using arrays and lists in Python programming. It explains what arrays and lists are, how to create and output lists, edit existing lists, and allow user input into lists. Example tasks and challenges are provided to help learners practice applying these list skills.

Uploaded by

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

Introduction to Python

Programming

Part 5: Arrays / Lists


How to use this resource
Skill Explanations: Pink Slides
• Within each unit, you will learn how to develop
and apply a range of Python programming skills.
Skill explanations are in pink.
Tasks: Rookie Pro Beast
• 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).
Challenges: Rookie Pro Beast
• 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!
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
Once you complete a skill, colour code Confidence
Contents Level
the box to show your level of
confidence. You can always revisit the Writing an array / list
skill later on to boost your confidence.
Understanding the structure of an
Colour
array / list
Key
Code Edit an array / list
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/Lists
• 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
1. Create a list to store the numbers 1 to 10.
2. Output the list.

Pseudo code Python

START
numbers = [1,2,3,4,5,6,7,8,9,10]
OUTPUT: numbers
END
Task 1: Solution
• Add a print screen to show • Add a print screen to show
your coding here. your output solution here.
Task 2: Rookie
1. Create a list to store 5 names of your choice.
2. Output the list.

Pseudo code Python

START
names = [Gareth, Lionel, Zlatan,
Rachel, Mia]
OUTPUT: names
END
Task 2: Solution
• Add a print screen to show • Add a print screen to show
your coding here. your output solution here.
Understanding Array/List structures
• A list is structured as follows:
Index 0 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

• 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.
Task 3: Understanding index
1. Output a specific value of a list by using this command:

2. Read the following lists. Using your understanding of list indexing, identify the correct data to
be output if the following commands were written;

List Command Output


12

Nintendo

Lucy

4
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
1. Create the following list in python:

2. 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.
Add a print screen of
your solutions to the
Programming Challenge: Rookie next slide.

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

1 Mark
Programming Challenge: Rookie - Answer
• Add a print screen to show • Add a print screen to show
your coding here. your output solution here.
Add a print screen of
your solutions to the
Programming Challenge: Pro next slide.

1. Create a list which includes all the days of the week


(Monday to Friday)
2. Append the days Saturday and Sunday to the end of
your list.
3. Print out your final list.

1 Mark
Programming Challenge: Pro - Answer
• Add a print screen to show • Add a print screen to show
your coding here. your output solution here.
Add a print screen of
your solutions to the
Programming Challenge: Beast next slide.

1. 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.
2. 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

1 Mark
Programming Challenge: Beast - Answer
• Add a print screen to show • Add a print screen to show
your coding here. 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:


tick

1 Mark
Complete the table below to help you identify what

Challenges Review areas you are confident at and which areas you need
to improve further:
Challenge Your Score (Max 1 mark each)
Rookie Challenge
Pro Challenge
Beast Challenge
Debugging Challenge

Unit Review
What Went Well:

Even Better If:

You might also like