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.7 – Modify

In the modify tasks, students adapt the example code to start to create code of their own.

Make sure that the students add comments to explain what the code does.


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