Learn String Manipulation by Building a Cipher - Step 28

Tell us what’s happening:

check my code out and tell me what im doing wrong

Your code so far


# User Editable Region

text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'
 for char in text:
text.lower()
index = alphabet.find(char)
print(char,index) 
pass

# 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/127.0.0.0 Safari/537.36 Edg/127.0.0.0

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 28

Check your indentation.

Also, you are still iterating over text

which line is it the “for”? cuz it tells me to do that
For now, instead of iterating over text , change the for loop to iterate over text.lower() .

This one:

Also, your for loop is not proper indented.

And what is the purpose of:

how do i change that?

it tells me to place a new line and put pass

Let’s reset the code and try again.

We have 2 variables:

text = 'Hello World'
alphabet = 'abcdefghijklmnopqrstuvwxyz'

And this for loop:

for char in text:
    index = alphabet.find(char)
    print(char, index)

This is a proper indented for loop.

What this loop does is iterating over text (which is a string "Hello World").
On each loop, it does 2 things:

    index = alphabet.find(char)
    print(char, index)

For example:

When char is the letter "H":

the letter "H" is not in the string "abcdefghijklmnopqrstuvwxyz"

so

alphabet.find(char)

will return -1, that means index is -1.

So

print(char, index)

will print out:

H -1

like you see on the console on the right.

And so on, when char is letter "e", "l", "l", "o", …
You can look at the console on the right to see the result.


The current for loop is iterating over text, right?

Now the instruction asked us to:

instead of iterating over text, change the for loop to iterate over text.lower()

so you have to make change to this line:

for char in text:

Side note:

text = 'Hello World'
text.lower()

will return the string "hello world"

thank you so much for helping but whenever i try to move the “for” it tells me to :Your code raised an error before any tests could run. Please fix it and try again.

or Your code has an indentation error. You may need to add pass on a new line to form a valid block of code.

No, no. After you reset the code, don’t move the for loop.
The given default for loop is perfectly indented as it is:

for char in text:
    index = alphabet.find(char)
    print(char, index)

All you need to do is edit this line:

for char in text:

to instead of iterating over text, we now iterating over text.lower().


You should consider to re-read the instruction on Step 24 to understand what indentation is and why we need it:

Learn String Manipulation by Building a Cipher - Step 24


And if you’re still struggle, you can share with us the update code.

You can post your updated code by put your code between 2 line of ``` (3 back ticks) (the back tick key is usually under the Esc key on your keyboard), like this:

```
# your code here
```

or you can use the Preformatted Text button:

do i delete the rest?

Sorry, I should be clearer.
When I said reset the code, I meant press the Reset button, not delete the code:

image

Do you make any change to your code? Can I see your updated code?

wouldnt that reset everything?

When you press the Reset button, it’ll reset the code to the default code when you first start the step. It doesn’t delete all the code.

The code after reset will look like this:

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

for char in text:
    index = alphabet.find(char)
    print(char, index)

Why we have to reset? We reset to undo the messed up indentation.
Now, we don’t have to worry about indentation anymore.
We only have to care about making change to this line:

for char in text:

to instead of iterating over text, we now iterating over text.lower() like the instruction asked.


PS:
A word of advice: I think you should go though each step slowly to make sure you really understand what the instruction said and what the code does before going to the next step.
Because it seem like you haven’t understand about indentation yet, which was explained before on Step 24.

thank you so much after taking a break I went through 20-28 and got it

1 Like