Tell us what’s happening:
Hello, Im stuck in the step 19 of the Cesar python of the new curriculum and I dont know What i’ve got wrong
Your code so far
# User Editable Region
def caesar(text, shift):
if not isinstance(shift, int):
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/138.0.0.0 Safari/537.36 OPR/122.0.0.0
Challenge Information:
Build a Caesar Cipher - Step 19
Please reset this step and try again. Don’t change the seed code, rather add another if statement as outlined in the instructions.
i’ve done it but it says this code: def caesar(text, shift):
if not isinstance(shift, int):
if shift<1:
return ‘Shift must be an integer value.’ is wrong
Please post your complete formatted code for this step.
def caesar(text, shift):
if not isinstance(shift, int):
if shift<1:
return ‘Shift must be a positive integer.’
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)
It looks like you did not reset this step to reinstate the seed code.
I did, i dont understand you? what do you mean by seed code?
def caesar(text, shift):
if not isinstance(shift, int):
return 'Shift must be an integer value.'
This is the seed code. Does this look like what you have there? Please click the “RESET” button to get that back and try again.
ok, did that, but my point was than i didint understand why if i have a second If that checks if shift<1 it says that the answer is wrong
so like why is this code wrong: [quote=“samuel062708, post:1, topic:766714”]
def caesar(text, shift):
if not isinstance(shift, int):
if shift<1 :
return 'Shift must be a positive integer.'
[/quote]
ok, forget it. I’ve resolved it afther a while.
I had the if nested inside the other if when I had to put it on the same level as the other if, so like this: 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.”