Try it:

Store and use lots of data in the same variable
Lists in python : Store and use lots of data in the same variable

Below you’ll see some example python code that contains a shopping list

Press Ctrl + Enter  to run the code.

This code starts by creating a list called shopping which contains "bananas", "oranges", "chocolate" and "toilet roll"

It then adds "pizza" to the end of the list and removes "chocolate"

Challenges:

Start by running the code.

  1. Add 'socks' to the shopping list

    There’s two ways to do to this. You could either add it on line 3 so that it’s one of the original values in the list or you could copy and paste line 9 to append "socks" to the end of the list.

  2. Remove 'oranges' from the list

    Again, there are two ways to do this. You could remove it from line 3 or use shopping.remove() 

  3. Add items to the list until there are exactly 10 items

    You can find out how many items are in a list using len(shopping) which calculates the length of the list called shopping. Just add more values until you’ve got 10 in total. 

On the next page you’ll get some code with both syntax and logic errors

KPRIDE

KPRIDE stands for Keywords, Predict, Run, Investigate, Debug and Extend and it’s a way of helping you explore and understand python code. Click on the image below for a set of KPRIDE activities for this python skill.

Page 1: Intro

Page 2: The theory: learn what you need to know as fast as possible.

Page 3: Try it: try out and adapt some working python code snippets.

Page 4: Debug it: Learn how to find and fix common mistakes.

Page 5: Extend it: Choose a project idea to use your newfound python skills.