Week 10

Lists of Treasures

Aim: Store several related values together.

New coding words

  1. list
  2. item
  3. index
  4. choice
  5. square brackets

What the coding words mean

  1. list: A collection of values stored together inside square brackets.
  2. item: One value stored inside a list.
  3. index: The numbered position of an item. Python starts at index 0.
  4. choice: An item selected from a list.
  5. square brackets: The symbols [ ] used to create a list or select an item.
Code along

Store and select list items

Store four fruits together and select items using their index numbers.

Python coding spaceReady to run
.py

Tab indents. Esc then Tab leaves the editor. Ctrl/⌘ + Enter runs your code.

Output (Shell)What your program does
Select Run my code to try this program.
Opening your coding space…Each activity has its own saved code.
Mini project

Silly Story Machine

Choose random items from three lists to make a silly sentence.

Python coding spaceReady to run
.py

Tab indents. Esc then Tab leaves the editor. Ctrl/⌘ + Enter runs your code.

Output (Shell)What your program does
Select Run my code to try this program.
Opening your coding space…Each activity has its own saved code.

Your mini-project to-do list

0 of 4 completed

Complete these activities in the mini-project editor above. After each change, select Run my code to check your program’s output or drawing.

Save your finished mini project

Select Download my work and save the file as week_10_silly_story_machine.py. The .py ending tells us that the file contains Python code. Keep this file as a copy of your finished program.

Debugging detective

Chi Opara, your course guide

Knowledge check

Question 1

What is the index of the first list item?

Choose one answer
Question 2
Python codepets = ["cat", "dog", "fish"]

What does pets[1] select?

Your answers are checked in this browser and are not submitted.

How are you getting on so far?

My checklist

Finished Week 10?

This progress is saved only in this browser.