+ 4
Secret message challenge
The output should be 'svool dliow' (input 'Helo world's) https://code.sololearn.com/cPyRSZl0TJqg/?ref=app
29 Réponses
+ 4
v is missing. ;)
+ 4
My short version of the solution.
https://code.sololearn.com/cdNVriqTwTYz/?ref=app
+ 3
https://code.sololearn.com/cRmiZjDhP42o/?ref=app
+ 3
Simple and efficient code👇👇✌️ :
import string
inp = (input()).lower()
alps = string.ascii_lowercase
l1 = []
for i in alps:
l1.append(i)
# print(l1, inp)
count = []
for i in inp:
try:
count.append(l1.index(i))
except ValueError:
count.append(" ")
# print(count)
str = ''
for i in count:
try:
str += l1[25-i]
except TypeError:
str += " "
print(str)
+ 2
Here is my solution:
https://code.sololearn.com/cuf2DhV4Z0Us/?ref=app
I just made a list of the letters in the alphabet, made a copy of it that was reversed, combined both lists in a dictionary, and replaced each letter in the input with the opposite letter.
(Better explained in the code.)
+ 2
message=input().lower()
alph="abcdefghijklmnopqrstuvwxyz"
p=""
for i in message:
for k in range(len(alph)):
if i==alph[k]:
h=alph[-k-1]
p+=h
if i==" ":
p+=" "
continue
print(p)
+ 2
import string
x = input().lower()
abcd = string.ascii_lowercase
dcba = abcd[::-1]
dict = dict(zip(abcd,dcba))
res = [dict[i] if i.isalpha() else i for i in x]
print("".join(res))
+ 2
Why you write so long code? You can do this very easy::::
import string
n = input().lower()
b = string.ascii_lowercase
for i in n:
pos = b.find(i)
print(b[-pos-1])
Here 6 line)
I fix some bags if you can do this yourself 😉😏
+ 1
Thank you!
+ 1
https://code.sololearn.com/cymXYyIAz23i/?ref=app
+ 1
Here's a different ASCII solution:
https://code.sololearn.com/cW38n9Sc6Ciw/?ref=app
+ 1
Another solution with 2 list
https://code.sololearn.com/cCpv60MG4auB/#py
+ 1
alpha = "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ"
reversed_alpha = alpha[::-1]
message = input()
coded = " "
for i in message :
coded += reversed_alpha[alpha.index(i)]
print(coded.lower())
0
Another OOP solution https://code.sololearn.com/ck2cT7xo18yY/?ref=app
0
My version...
https://code.sololearn.com/c0nLdBhOHu45/?ref=app
0
This is the solution for the code coach secret message problem in my version:
https://code.sololearn.com/ca17A4a25a0a/#py
0
Thanks for the post.
Helped me figure out why I was printing either each inverted letter on a separate line and not being able to combine it into a single line output.
https://code.sololearn.com/cA12a16a13A1
0
Here is my solution
https://code.sololearn.com/cw3nAZ7XlV05/?ref=app
0
import re
message = input()
alfabet = ["a","b","c","d","e","f","g","h", "i", "j", "k", "l", "m", "n",
"o","p","q","r","s","t","u","v","w","x","y","z", " "]
def cnv_secr(xxx):
lst = []
for i in xxx:
for index, letter in enumerate(alfabet, start=1):
if i.lower() == letter:
lst.append(index)
string = ""
for i in lst:
for index, letter in enumerate(alfabet[::-1]):
if i == 27: # make do!!
letter = ' '
string += letter
elif index == i:
string += letter
print(re.sub(' +', ' ', string))
cnv_secr(message)