Back to Freecodecamp

Step 4

curriculum/challenges/english/blocks/workshop-caesar-cipher/680a549f60f5a3fedfc0edd9.md

latest1.7 KB
Original Source

--description--

As you can see from the output, the shifted alphabet starts at the letter f because shift has the value 5. But now the first five letters of the alphabet – a, b, c, d and e – are missing from the shifted alphabet, so you'll need to add them at the end of the shifted alphabet.

The + operator is used to combine two or more strings together in a process called concatenation like this:

py
greeting = 'Hello' + ' ' + 'World'
print(greeting) # Hello World

Modify the existing assignment of the shifted_alphabet variable: use the slicing syntax to extract the missing first portion of alphabet and concatenate it to alphabet[shift:].

As a reminder, sentence[start:stop] returns the characters of sentence from position start (included) to stop (excluded).

--hints--

You should not directly modify the alphabet variable.

js
({ test: () => runPython(`
  assert alphabet == "abcdefghijklmnopqrstuvwxyz"
`) })

You should assign the concatenation of alphabet[shift:] and the missing first portion of alphabet to the shifted_alphabet variable on the same line it was declared. Use shift to specify where to stop the slicing.

js
({ test: () => runPython(`
_shifted_alpha = _Node(_code).find_variable("shifted_alphabet")
_first = _shifted_alpha.is_equivalent("shifted_alphabet = alphabet[shift:] + alphabet[:shift]")
_second =_shifted_alpha.is_equivalent("shifted_alphabet = alphabet[shift:] + alphabet[0:shift]")
assert _first or _second
`) })

--seed--

--seed-contents--

py
alphabet = 'abcdefghijklmnopqrstuvwxyz'
shift = 5
--fcc-editable-region--
shifted_alphabet = alphabet[shift:]
--fcc-editable-region--
print(shifted_alphabet)