Learn String Manipulation by Building a Cipher - Step 50

Tell us what’s happening:

Not sure what I am doing wrong here, have tried multiple variations of indents and argument pass through for the custom function of “caesar”.

Returning the error: Your code raised an error before any tests could run. Please fix it and try again.

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; rv:122.0) Gecko/20100101 Firefox/122.0

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 50

Welcome to the forum @jm.windle

  1. remove the space after the colon for the caesar function
  2. indent the code after the if and else statements

Happy coding

This worked thank you.

Did some testing, the space after the colon does not effect the outcome. Is there another reason I should be ensuring no extra spaces?


Do you mean it doesn’t affect the test, or the program output?

The tests are sometimes overly strict. It shouldn’t matter if you have an extra space at the end of your line. Although it’s unecessary, it wouldn’t affect execution of a Python program.

1 Like