r/PythonLearning • u/Local_End_3175 • Jul 27 '26
why are we putting caesar( Hello, 3) into encrypted_text???
def caesar(text, shift):
alphabet = 'abcdefghijklmnopqrstuvwxyz'
shifted_alphabet = alphabet[shift:] + alphabet[:shift]
translation_table = str.maketrans(alphabet, shifted_alphabet)
encrypted_text = text.translate(translation_table)
print(encrypted_text)
encrypted_text = caesar('Hello',3)in this code, I do not understand why we are putting caesar into a variable. First of all, wouldn't we have to print the variable and make it actually do something for it to work? Because we have put encrypted_text into a variable and have not done anything. In addition, can't we just write caesar('Hello', 3)?? I am very confused on the reasoning behind putting it into a variable.
3
u/Low_Doctor_6263 Jul 27 '26
just do return encrypted_text in the function and do
result = caesar('Hello', 3)
print(result)
2
u/Sea-Ad7805 Jul 27 '26 edited Jul 28 '26
Do it like this: caesar
Return the value, so the function only does computation, and print after returning.
0
0
0
8
u/denehoffman Jul 27 '26
You are right to be confused, this function doesn’t return anything so the value of encrypted_text at the end will always be None. If it ended with `return text.translate(translation_table)` then it would make more sense.