Back to Freecodecamp

Step 23

curriculum/challenges/english/blocks/learn-string-manipulation-by-building-a-cipher/65521203d7165c7b84b22ad4.md

latest1.9 KB
Original Source

--description--

A loop allows you to systematically go through a sequence of elements and execute actions on each one.

In this case, you'll employ a for loop. Here's how you can iterate over text:

py
for i in text:

for is the keyword denoting the loop type. i is a variable that sequentially takes the value of the elements in text. The statement ends with a colon, :.

Below the line where you declared alphabet, write a for loop to iterate over text. Use i as the loop variable.

Doing so, there is an error in the terminal. You will learn about it in the next step.

--hints--

You should use the for keyword to create a loop. Make sure to place the for keyword at the beginning of the line and leave a white space after the keyword.

js
const commentless_code = __helpers.python.removeComments(code);
assert.match(commentless_code, /^for\s+/m)

You should write the i variable after the for keyword.

js
const commentless_code = __helpers.python.removeComments(code);
assert.match(commentless_code, /^for\s+i/m)

You should write the in keyword after for i . Make sure to leave a space around the in keyword.

js
const commentless_code = __helpers.python.removeComments(code);
assert.match(commentless_code, /^for\s+i\s+in\s+/m)

You should write text after for i in . Don't forget to add the final :.

js
const commentless_code = __helpers.python.removeComments(code);
assert.match(commentless_code, /^for\s+i\s+in\s+text\s*:\s*$/m)

Your for loop should be placed below the line of code alphabet = 'abcdefghijklmnopqrstuvwxyz'.

js
const commentless_code = __helpers.python.removeComments(code);
assert.match(commentless_code, /^alphabet\s*=\s*("|')abcdefghijklmnopqrstuvwxyz\1\s*^for\s+i\s+in\s+text\s*:\s*$/m)

--seed--

--seed-contents--

py
--fcc-editable-region--
text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'

--fcc-editable-region--