I dont get it.
I can place the .upper() were every i want, its every time wrong.
in my oppinion , it has to be placeed at the end of the return comand.
But codecamp always say it has to be right in the str.maketrans Method…what do i wrong?
where must the .upper() method be placed at?
Thanks a lot
Your code so far
def caesar(text, shift):
alphabet = 'abcdefghijklmnopqrstuvwxyz'
shifted_alphabet = alphabet[shift:] + alphabet[:shift]
# User Editable Region
translation_table = str.maketrans(alphabet, shifted_alphabet)
# User Editable Region
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/150.0.0.0 Safari/537.36
The translation table is where your code will look to replace each alphabet character in text with the shifted_alphabet character that is shift places to the right of it.
Give yourself a visual by printing alphabet and shifted_alphabet one right after the other. See how the ‘a’ in alphabet maps directly to the ‘d’ in shifted_alphabet at the same index?
maketrans makes that mapping but converts the letters to ASCII codes. Try printing translation_table so you can see what that looks like.
Notice that currently there are no uppercase characters inshifted_alphabet and alphabet, which are used to make the translation table, so translate can’t find any uppercase letters in text to encrypt.
This step is about adding the uppercase version of alphabet and shifted_alphabet to their lowercase versions so translate can find both uppercase and lowercase characters in text.
It is great that you solved the challenge, 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.