Learn String Manipulation by Building a Cipher - Step 47

Tell us what’s happening:

The code seems fine but I cannot understand why it is still giving a problem in the recall of the function

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
        else:
            index = alphabet.find(char)
            new_index = (index + shift) % len(alphabet)
            encrypted_text += alphabet[new_index]
    return encrypted_text
        
encrypted_text = caesar()
print('plain text:', text)
print('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/120.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 47

Hello davide,

There seems to be 3 things, you changed the indentation of the print methods. They are supposed to be inside the caesar method, now they aren’t.
You also seem to have added a return statement, I don’t think the question asked for that.
For the last one, you just have to call the caesar() method, you don’t have to assign the result to anything.

You were only asked to call your caesar function and where to do it was at the end of your code. after that indent your two print calls properly.

1 Like

thank you very much !!

I didn’t get any of this at all i tried to call the function but I don’t know how to call it
I understand I have to call it at the end of the code outside the for loop
my question is how do I write the last line of code ?

Hey @wayne.hated , welcome to the forum!

If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Ask for Help button located on the challenge (it looks like a question mark). This button only appears if you have tried to submit an answer at least three times.

The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.

1 Like

Here is some info on how to call a function in Python, it will answer your question:

https://www.freecodecamp.org/news/how-to-call-a-function-in-python-def-syntax-example/#howtocallafunctioninpython

https://www.w3schools.com/python/python_functions.asp

If you still have a question please open a new topic as suggested, thanks!