Build a Caesar Cipher - Step 20

Tell us what’s happening:

Can someone explain to me why the code raises an error?

Your code so far

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

# User Editable Region
#When adding this if-block I got the error.
    if (25 < shift) or (shift < 1):
        return 'Shift must be an integer between 1 and 25.'


# 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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.3 Safari/605.1.15

Challenge Information:

Build a Caesar Cipher - Step 20

The solution was to replace the first if-block with:

if isinstance(shift, bool) or not isinstance(shift, int):
return ‘Shift must be an integer value.’

The issue was caused by Python treating bool as a subclass of int.

Removing the parentheses here passes the test for some reason:

if shift < 1 or shift > 25:

Perhaps an editor quirk.

you were asked to add the second condition after shift < 1 notice that you added it before