Fikman
1
Tell us what’s happening:
I am stranded again, someone please assist me with this
Your code so far
# User Editable Region
alphabet = 'abcdefghijklmnopqrstuvwxyz'
shift = 5
shifted_alphabet = alphabet[shift:] + alphabet[:shift]
translation_table = str.maketrans(alphabet, shifted_alphabet)
text = 'hello world'
encrypted_text = text.translate(translation_table)
print(encrypted_text)
def caesar(encrypted_text):
alphabet = 'abcdefghijklmnopqrstuvwxyz'
shift = 5
shifted_alphabet = alphabet[shift:] + alphabet[:shift]
translation_table = str.maketrans(alphabet, shifted_alphabet)
# User Editable Region
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 10
Put all your existing code within the function body.
This should be interpreted as move or cut and paste. You should not end up with duplicate lines of code.
Fikman
3
Can shed more light on this statement: “You should not end up with duplicate lines of code.”
You have lines of code that are the same outside and inside your function
alphabet is defined twice.
shift is definied twice.
alphabet = 'abcdefghijklmnopqrstuvwxyz' # duplicate
shift = 5
shifted_alphabet = alphabet[shift:] + alphabet[:shift]
translation_table = str.maketrans(alphabet, shifted_alphabet)
text = 'hello world'
encrypted_text = text.translate(translation_table)
print(encrypted_text)
def caesar(encrypted_text):
alphabet = 'abcdefghijklmnopqrstuvwxyz' # duplicate
shift = 5
shifted_alphabet = alphabet[shift:] + alphabet[:shift]
translation_table = str.maketrans(alphabet, shifted_alphabet)
Put all your existing code within the function body.
Don’t modify any lines.
alphabet isn’t a valid line of code.
Move all your existing code within the function body.
Really just put “def caesar” at the top and indent the rest.
existing code
existing code
To make that code a function:
def function():
existing code
existing code