Learn String Manipulation by Building a Cipher - Step 16

Hi, I don’t know if it’s just late and I’m not getting it, but how do I connect the alphabet part to the index and shift. Can anyone help?

The steps are:
As you can see from the output, "h" is at index 7 in the alphabet string. Now you need to find the letter at index 7 plus the value of shift. For that, you can use the addition operator, +, in the same way you would use it for a mathematical addition.

Declare a variable named shifted and assign it the alphabet letter at index plus shift.

My code so far:

text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'
index = alphabet.find(text[0].lower())
print(index)
shifted = alphabet.find(index + shift)

Please post a link to the step. Thanks


Here, index + shift is a number, and I don’t think you’ll find a number in the alphabet, so something has to have got awry here.

I’ve added the instruction it gave for the step

It helps if you post the link to the step itself so I can run some code!

You shouldn’t be using find here.

The phrase “alphabet… at” is a hint to use bracket notation to index into the alphabet string at the location index + shift

Here is the link:

I don’t understand how to word it though. Is it just alphabet = [index+shift]?

I feel like steps have been missed

Indexing into a string was part of this step: https://www.freecodecamp.org/learn/scientific-computing-with-python/learn-string-manipulation-by-building-a-cipher/step-4

I got it!

MOD edit solution removed

It wasn’t clear what I was asked to do on this one.

2 Likes

It is great that you solved the challenge, but please don’t your full working solution,

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.