Learn String Manipulation by Building a Cipher - Step 50

Tell us what’s happening:

My code keeps giving, ‘Your code raised an error before any tests could run. Please fix it and try again.’ even though i indented the code correctly? There any way to fix this on why my code doesn’t work at all.

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('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/ Safari/537.36 OPR/

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 50

These print statements should be inside your function

if you press F12 to open the browser console you should see the error:

You can read that on line 17 there is an error NameError: name 'encrypted_text' is not defined

indent all the following lines to give your new function a body

Without the proper indentation, your print statements are not inside the function. So they are trying to access variables scoped to the function from outside it.

You only need to do your print commands which will be inside the def give a tab to your print commands which are at the bottom…error fixed

— removed —

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.