# User Editable Region
def caesar(text, shift):
if not isinstance(shift, int):
return 'Shift must be an integer value.'
# 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 ist: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36
Hi there and welcome to the forum!
Please tell us what error messages you have received and what you have done to fix them.
It will be much easier for us to help you with this information.
Thanks
It works now, but I don’t know why! What’s the point of checking for True here? I didn’t understand the IF construct that way. In this case, the result is wrong, since Shift is an INT. How does IF know that the query refers to Shift and not text?
The bool isn’t necessarily what the if statement wants it’s just holding the place for “True“ for something that will be asked later on that should be true. a few steps later it asked for “if shift < 1 or shift > 25: …” and that beeing true is necessary. i think you have already understood what i mean since your topic is a month old but i say this for the next people that have the same question in mind.
Have fun programming with python!
Keywords for when someone looks for this: Caesar cipher step 16 step 17 step 18 if True