Build a Caesar Cipher - Step 19

Tell us what’s happening:

I tried adding only the if condition but getting error. Anyone can help pls.

Your code so far


# User Editable Region

def caesar(text, shift):
    if not isinstance(shift, int):
        return 'Shift must be an integer value.'
        if (shift<1):
            return 'Shift must be a positive integer.'

# User Editable Region

    alphabet = 'abcdefghijklmnopqrstuvwxyz'
    shifted_alphabet = alphabet[shift:] + alphabet[:shift]
    translation_table = str.maketrans(alphabet + alphabet.upper(), shifted_alphabet + shifted_alphabet.upper())
    return text.translate(translation_table)


encrypted_text = caesar('freeCodeCamp', 3)
print(encrypted_text)

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36

Challenge Information:

Build a Caesar Cipher - Step 19

Therefore, after your first if statement, create another if statement

“After” means it should be below and at the same level of indentation. If it’s indented, it means it’s “inside” your if statement and after return.

If it’s after return like that it should be a red flag, because code after return will never run. return will exit the function first.

1 Like

i have a question for the same step.

i have it all as it should but it says that there was a problem and couldnt run. here’s my code:

def caesar(text, shift):

if not isinstance(shift, int):

    return 'Shift must be an integer value.'



if shift<=1:

    return "Shift must be a positive integer."



alphabet = 'abcdefghijklmnopqrstuvwxyz'

shifted_alphabet = alphabet\[shift:\] + alphabet\[:shift\]

translation_table = str.maketrans(alphabet + alphabet.upper(), shifted_alphabet + shifted_alphabet.upper())

return text.translate(translation_table)

encrypted_text = caesar(‘freeCodeCamp’, 3)

print(encrypted_text)

Hello @alexfrager28 , welcome to freeCodeCamp ! :waving_hand:

What are the test saying to you exactly ? If it is something like “Your code raised an error before testing. Please try again.”, it is because there is an error in your code that stops the Python from running (ex : SyntaxError, IndentationError, etc).

Is your code indented exactly like sou showed ?

In the future, please create your own topic when you have specific questions about your own challenge code. Only respond to another thread when you want to provide help to the original poster of the other thread or have follow up questions concerning other replies given to the original poster.

The easiest way to create a topic for help with your own solution is to click the Ask for Help button located on each challenge. This will automatically import your code in a readable format and pull in the challenge url while still allowing you to ask any question about the challenge or your code.

Thank you.

1 Like

yes, it is, it is directly below the last if statement, and it does say” your code raised an error before testing…”

ill open a new thread, i didnt know how to make a new one, so thanks