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.

CodeSports

11-02-Len-Investigate

Instructions

Inspect the code carefully and write a prediction in the comments about what it will do.

  • Run the code and compare the result to their prediction.

Learning Objectives/Goals

Be able to read, comprehend, trace, adapt and create Python code using selection that:

  • Uses len to count the number of characters in a string

Len function

The **len() **function returns the number of characters in a string. It takes the string as its parameter.

Example

This code gets input, stores it in the word variable and finds out how many characters are in it.

print("Enter a word")
word = input()

Uses the len() function as part of the print() function. Removes the need for the word_length variable.

print(len(word))

Help! My Code Does Not Work!

Make sure that you check for the following things:

  • len is lower case
  • the length of the string has been assigned into a variable
  • spaces are characters too!

Hints