Build a Caesar Cipher - Step 20

Tell us what’s happening:

Comme vous l’avez déjà vérifié, le décalage utilisé pour chiffrer le texte doit être positif. Il ne peut cependant pas dépasser 25(le dernier indice de alphabet).

Ajoutez une seconde condition à l’ ifinstruction qui vérifie que shiftest supérieur à 25. N’oubliez pas que l’opération logique OU en Python est implémentée via l’ oropérateur OU.

Veuillez également mettre à jour le message renvoyé en Shift must be an integer between 1 and 25.

Your code so far

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

# User Editable Region

    if shift < 1:
        return 'Shift must be a positive integer.'
    if shift > 25 :
        print('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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36

Challenge Information:

Build a Caesar Cipher - Step 20

In this step, you are asked to add a second condition to the existing if condition using an or operator. You are not asked to create an additional if statement.

You are also asked to update the message returned if the if statement evaluates to True.

code removed by moderator

It is great that you solved the challenge @aoc82500, 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. How to Help Someone with Their Code Using the Socratic Method

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.