Learn String Manipulation by Building a Cipher - Step 50

Tell us what’s happening:

my function works when I call it, but it’s still not correct?

Your code so far

# User Editable Region

text = 'Hello Zaira'
shift = 3

def caesar():
    alphabet = 'abcdefghijklmnopqrstuvwxyz'
    encrypted_text = ''
    for char in text.lower():
        if char == ' ':
            encrypted_text += char
            index = alphabet.find(char)
            new_index = (index + shift) % len(alphabet)
            encrypted_text += alphabet[new_index]
        print('encrypted text:', encrypted_text)
print('text:', 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/ Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 50

1 Like

Hello @Arod1991!

Indenting is very important in Python. The code you posted is indented properly except for the final two print statements. Additionally, there is a call to the caesar function which shouldn’t be there.

It might be best in this situation to reset the step and start again from afresh.

Does this help?

Keep up the good progress!

Happy Coding! :slightly_smiling_face:

thank you so much @ios-man , it works now!

1 Like