Learn String Manipulation by Building a Cipher - Step 23

Hi good evening I’m a new student and I try to do the exercise for my own. But I stocked in this chapter 23, I had read that you describe avobe and I use it , but it doesnt work can you help me please? thankyou

I do this:
text = ‘Hello World’
shift = 3
alphabet = ‘abcdefghijklmnopqrstuvwxyz’

for char in alphabet:
index = alphabet.find(char)
print(f"alphabet: {char}, Index: {index}")

Your code so far


/* User Editable Region */

text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'

index = alphabet.find(char)

for char in alphabet:
    print(f"alphabet: {char}, Index: {index}")


/* User Editable Region */

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 23

This is how you declare a variable called text.

declare a variable called index

How would you do that?

index = 5 + 5

This how to assign the value returned by 5 + 5 to index

assign the value returned by alphabet.find(char) to this variable.

Then, after that on a new line, keep the existing print(char). You might want to reset the lesson.

I do it but it doesnt work

index = alphabet.find(char) because this was want in the exercise

Step 23

Before printing the current character, declare a variable called index and assign the value returned by alphabet.find(char) to this variable.

Apologies, I missed that you already had that line!

Before printing the current character

Just put that line RIGHT before the original print (reset the lesson or add it back in). Don’t modify the print line if it’s not in the instructions.


nop it doesnt work, thanks buddy for your help

I cant see what is wrong with my code¡¡¡¡

char doesn’t exist outside of the loop, so you can’t use it outside of the loop

Put that line before the print, not before the for loop.

As @ilenia mentioned the char variable doesn’t exist yet until it’s created by the for loop

ok I did it. But when you gonna click in the buton to pass, isnt work¡¡
I don’t know what can I do

Try to change/add only what the instructions ask. You are iterating over alphabet instead of text.

1 Like

I’m too stuck on the same Question.

1 Like

hey @Ashyyy

If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Ask for Help button located on the challenge (it looks like a question mark). This button only appears if you have tried to submit an answer at least three times.

The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.

1 Like

Your code is all good apart from one thing.
Try to iterate using text and not alphabet.

text = ‘Hello World’
shift = 3
alphabet = ‘abcdefghijklmnopqrstuvwxyz’
for char in text
index =alphabet.find(char)
print(text)

1 Like

Finally achieved after 15 min of thinking
SOLUTION REMOVED

Please don’t post solution code, thanks!

And if you have questions please open a new topic :+1: