0
Caesar cipher
Apparently, I’m trying to recreate the Caesar cipher in python. However, the “shift” function isn’t working. It’s supposed to add the same key to every letter in the message. (excluding spaces) https://sololearn.com/compiler-playground/c2Iz12HWaez5/?ref=app
9 ответов
+ 2
Annihilate
If you want to update an element in a list, you must provide the index of the element.
l=list(lst)
for i in l:
if i not in alphabet:
l[i]=" "
continue
else:
l[i]=alphabet.index(i)
In this part of code, the "i" in l[i] is a string...
+ 4
Annihilate
Welcome back to Python.
There are many caesar cipher code in Code Bits for you to study.
I also created one a month ago (well... Caesar is misspelled in the name...)
As Wilbur Jaywright suggested, using a alphabet variable can save many lines of code and add readability.
And in your code, you forget to handle "space" character which is in your "shift" to-do list.
Maybe this little code helps you recall what you learned.
https://sololearn.com/compiler-playground/cm7JC4N4AqfP/?ref=app
+ 3
You didn’t indent any code under shift, so the function does nothing.
Also, generally you should not be using more than five or so if statements in a row. You could make this code far more space efficient with an ALPHABET variable set to a string of the alphabet in order, and calling its index method.
+ 1
Wilbur Jaywright
I'm replying to the question as OP updated his code and mentioned the "let_to_num" function is not working...
0
Wong Hei Ming
Nice, but I want to break it down into these functions
0
Also, now the let_to_num function isn’t working
0
Wong Hei Ming please ask that in a new question post, as it does not seem related to this one.
0
Wong Hei Ming
i is holding each character in the message. (including spaces)
0
Wong Hei Ming
Ok, got it