Learn String Manipulation by Building a Cipher - Step 48

Tell us what’s happening:

You should print 'encrypted text:', encrypted_text after your for loop. Code does not pass.

Your code so far


# User Editable Region

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

for char in text.lower():
    if char == ' ':
        encrypted_text += char
        print('encrypted_text:', encrypted_text)
    else:
        index = alphabet.find(char)
        new_index = (index + shift) % len(alphabet)
        encrypted_text += alphabet[new_index]
    print('char:', char, 'encrypted_text:', encrypted_text)

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

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 48

The line is indented to be part of the loop still. It needs to be after, outside, thr loop.

Also copy paste the string to be printed or double check it

Hi @hzz19,
Great work.

  1. Create a new print function below the for loop. Not indented under the loop. Meaning let be on it own line separated from the for loop.
  2. Inside the bracket, put the encrypted text. Part of the current print function you are to cut away and put in the new print.

This should work. Let us know if it does.
:+1: happy coding.

Still does not pass.

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

for char in text.lower():
    if char == ' ':
        encrypted_text += char

    else:
        index = alphabet.find(char)
        new_index = (index + shift) % len(alphabet)
        encrypted_text += alphabet[new_index]

print('encrypted_text:', encrypted_text)

Code does not pass.

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

for char in text.lower():
    if char == ' ':
        encrypted_text += char

    else:
        index = alphabet.find(char)
        new_index = (index + shift) % len(alphabet)
        encrypted_text += alphabet[new_index]

print('encrypted_text:', encrypted_text)

Hi @hzz19 ,
Sorry about that.

The goal is to print at once on a single line the encrypted string.
Hence, the previous print function remains where it is. But only the encrypted part of that function is to be cut out to another print function on a separate line outside (i.e below) of the for loop .

Hope this helps you further.

The earlier print function should not be totally removed. Only the encrypted parameter of that fucntion is to be moved as you’ve done.

Now you know what’s missing. The previous print function without the encrypted part.

:+1: happy coding.

Hi @hzz19 ,
Sorry about that.

The goal is to print at once on a single line the encrypted string.
Hence, the previous print function remains where it is. But only the encrypted part of that function is to be cut out to another print function on a separate line outside (i.e below) of the for loop .

Hope this helps you further.

Instructions say to print:

'encrypted text:', encrypted_text

You are printing:

'encrypted_text:', encrypted_text

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