Learn String Manipulation by Building a Cipher - Step 43

Tell us what’s happening:

how is this not the correct code, its so simple but not even AI is helping, it says i have to indent the text after print() but i already have

Your code so far


# User Editable Region

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

for char in text.lower():
    if char == ' ':
        encrypted_text += char
    else:
        print()
        index = alphabet.find(char)
        new_index = index + shift
        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/137.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 43

1 Like

Hi you’re very close! Here’s are few hints:

  1. in the else block, think about whether you really need to use print() twice. Is that the best approach?
  2. Also, consider the last print() statement that shows the character, the encrypted text, should it be inside the else block, or outside?

Good luck! Let us know if you still need help!

i got it earlier, wasnt really using my head tbh - thanks anyway!

1 Like