Tell us what’s happening:
The program tells me, there is an error. But I tried it in PyCharm and it works. What is wrong?
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.’
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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36 Edg/140.0.0.0
Challenge Information:
Build a Caesar Cipher - Step 19