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


Make

In the make tasks, students use the skills learned in the earlier stages of PRIMM to create their own program based on a description of what it should do.

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


Substrings

A substring returns a sequence of characters from a string. Python uses slices to do this.

Slices treat strings like lists. Each character is given an index number starting with 0.

[0,1,2,3,4,...]

The slice uses two indexes, the start character and the end character (NOTE the end character is NOT INCLUDED in the slice).

The slice indexes come in brackets after the string or the variable containing the string.

# Outputs 'ompu'
print("Computing"[1:5])

word = "dalmatian"

# Outputs 'ma'
print(word[3:5])

Help! My Code Does Not Work!

Make sure to check your code for the following things:

  • The start and end indices are surrounded by square brackets
  • The start and end indices have a colon : between them.
  • The end index is one more than the character you want to stop on.

Hints