Learn String Manipulation by Building a Cipher - Step 34

Tell us what’s happening:

Describe your issue in detail here.

Your code so far


# User Editable Region

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

for char in text.lower():
    index = alphabet.find(char)    
    new_index = index + shift
    new_char = encrypted_text
    print('char:', char 'encrypted_text:', encrypted_text)

# User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 34

You appear to have created this post without editing the template. Please edit your post to Tell us what’s happening in your own words.

'new char:', new_char

Just like the string has no underscore here _ and the variable does have an underscore

'encrypted_text:', encrypted_text

You need to copy that format

updated version

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

for char in text.lower():
    index = alphabet.find(char)    
    new_index = index + shift
    new_char = alphabet[new_index] 
    encrypted_text += new_char
    print('char:', char,'encrypted text:', encrypted_text)

Can you please explain:

  • What step you are on?
  • What you are trying to do
  • If you have a question or there’s something you don’t understand?

Now you need to create a new_char variable at the end of your loop body. Set its value to alphabet[new_index].

This is the instruction for Step 34, it appears you’ve done this.

Are you passing the test now?

Nope it doesn’t let me pass im not sure what I am doing wrong

Hi @natalie888

It looks like you are on step 40.

code block removed

When I replace new_char with the code in the above code block, for the compound assignment code, the tests pass.

I am on step 34 not 40.

Here is the instructions for step 34:

Now you need to create a new_char variable at the end of your loop body. Set its value to alphabet[new_index].

Your code does not match this step. You should try to reset the lesson and try it again.

i already did that. can you tell me which step I went wrong

You have some extra code after that. Reset the lesson and try it again?

If it doesn’t work please share the updated code.

These lessons were just updated, that might be causing some problem.

The extra code is so that new_char is replaced. This means the print function will also be changed to encrypted. I’m not sure which step went wrong.

You can’t have “extra code”.

Here is the code from the step:

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

for char in text.lower():
    index = alphabet.find(char)
    print(char, index)
    new_index = index + shift

Step 34
Now you need to create a new_char variable at the end of your loop body. Set its value to alphabet[new_index].

Now where did this come from:

   encrypted_text += new_char
   print('char:', char,'encrypted text:', encrypted_text)

my step 34 is Now, replace new_char with encrypted_text . Also, modify the print() call to reflect this change.I have to use print() and i did not get the same original code as you

Screenshot 2024-02-01 122401

As I mentioned, the lessons were updated recently. You might have an older version which is cached and causing problems.

Try to reset the lesson and refresh the page (use Shift+Refresh to load a new page and replace your cached version).

The updated version you posted 3 days ago looked correct for the given instructions, but it’s impossible for me to verify it like this.

It glitched it is actually step 38

1 Like

nevermind i got it thanks tho

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