Tell us what’s happening:
Sono allo step 22 per il cifrario di Cesare.
def caesar(text, shift, encrypt=True):
if not encrypt:
shift = -shift
dovrebbe essere giusta ma a quanto pare non mi fa andare avanti perchè dice che ci sono errori, inoltre se guardo lo schermo sulla destra mi dice che il modulo 14 e l’alfabeto non è definito, quando in realtà sono tutti i moduli precedenti. Cosa posso fare? Grazie a chi mi aiuterà
Your code so far
def caesar(text, shift, encrypt=True):
if not isinstance(shift, int):
return 'Shift must be an integer value.'
if shift < 1 or shift > 25:
return 'Shift must be an integer between 1 and 25.'
alphabet = 'abcdefghijklmnopqrstuvwxyz'
# User Editable Region
def caesar(text,shift,encrypt=True):
if not encrypt:
shift = -shift
# User Editable Region
shifted_alphabet = alphabet[shift:] + alphabet[:shift]
translation_table = str.maketrans(alphabet + alphabet.upper(), shifted_alphabet + shifted_alphabet.upper())
encrypted_text = text.translate(translation_table)
return encrypted_text
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/143.0.0.0 Safari/537.36
Challenge Information:
Build a Caesar Cipher - Step 22