replit

Before you start this course, you must login to Replit

If you have forgotten your Replit account user name or password, ask your Coder Coach.

CoderSports


12.6 – Investigate

The ‘investigate’ stage gives students some example code and asks them questions about it to check their understanding. I use the block model to plan my questions. Try it, it’s really useful.


In this unit you will learn about: Lists

It is possible to output some consecutive items from a list by customising the print function to add a start and end index for the output.

There are a couple of traps to be careful of here.

The start value IS included in the output.

The end value IS NOT included in the output.

CODE EXAMPLES

# Create and populate a list
countries = ["UK", "USA", "Chad", "Australia", "Thailand"]

# Outputs 'USA', 'Chad', 'Australia'

print(countries[1:4])

# Outputs from the beginning of the list to 'Chad'.

print(countries[:3])

# Outputs from 'USA' to the end of the list.

print(countries[1:])

Help! My Code Does Not Work!

  • Square brackets for items in the list.
  • Commas between each item in the list.
  • String items are in quotation marks.
  • Range – the end value is NOT included in the output.
  • Search – not initialising counter OUTSIDE the loop.
  • Search – not incrementing counter INSIDE the loop.

Hints