+ 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

8th Apr 2023, 9:06 AM
Matt Osmond
Matt Osmond - avatar
4 Respuestas
+ 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)
8th Apr 2023, 9:41 AM
Hadrien BASSERY
Hadrien BASSERY - avatar
+ 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)
8th Apr 2023, 10:50 PM
Matt Osmond
Matt Osmond - avatar
+ 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!
8th Apr 2023, 10:29 PM
Matt Osmond
Matt Osmond - avatar
+ 1
ók éliminate the capitols reverses
9th Apr 2023, 7:43 AM
Elaina Spangler
Elaina Spangler - avatar