+ 2
My ADHD meds have worn off and I'm coding with no brain -- could anyone help me fix a simple cipher in Python?
Replace a with z, b with y, etc in a given string of text as input https://code.sololearn.com/cZHKIsH7phxa/?ref=app
4 Antworten
+ 6
Here is your reverser :
secretMessage = list(input(""))
alphabet = "abcdefghijklm nopqrstuvwxyz"
reverse = alphabet[::-1]
new = []
for i in secretMessage:
place = alphabet.index(i)
new.append(reverse[place])
new = "".join(new)
print(new)
+ 2
This is the code I ended up going with, that takes into account whitespace in the input string and normalises all characters to lowercase before checking them against the alphabet. It solves the code coach :)
secretMessage = str(input())
lowercase = secretMessage.lower()
alphabet = "abcdefghijklmnopqrstuvwxyz"
alphaList = list(alphabet)
reverse = alphabet[::-1]
cipher = ""
for i in lowercase:
if i == " ":
cipher += " "
elif i != " ":
place = alphaList.index(i)
cipher += reverse[place]
else:
pass
print(cipher)
+ 1
This was ultimately useful as a jumping-off point, but the code was not equipped to deal with strings containing spaces or capital letters, so I had to modify the input variables and then the output in order to preserve the spaces and eliminate capital letters. Thanks for your help!
+ 1
ók éliminate the capitols reverses