+ 1
Is there a simpler way to write this code?
I apologise for the spoiler if you've not tried the secret message code master problem. I wrote this to solve the secret message problem, it works perfectly but I can't help thinking there's an easier way to solve this, probably using regular expressions(import re). If you have a smarter way of solving the problem, please help me out. https://code.sololearn.com/cxamH2B926gD/?ref=app
10 Antworten
+ 4
Here's one
import string
str=input().lower()
print(''.join([string.ascii_lowercase[25-ord(i)%97] if i != ' ' else ' ' for i in str]))
+ 5
x = input().lower()
abc = 'abcdefghijklmnopqrstuvwxyz'
d = dict(zip(abc, abc[::-1]))
print("".join(d.get(s, s) for s in x))
+ 3
Here is another one:
import string
letters = list(string.ascii_lowercase)
d = dict(zip(letters,letters[::-1]))
m = input().lower()
r = ""
for l in m:
if (l != " "):
r += (d[l])
else:
r += " "
print(r)
+ 3
#what about this one?
alpha="abcdefghijklmnopqrstuvwxyz"
table=str.maketrans(alpha,alpha[::-1])
text=input().lower()
print(text.translate(table))
+ 1
Sousou your code gives error for white space, it's missing a " if i != ' ' else ' ' " statement just before the for loop in the print argument
+ 1
Akinlade Babatunde , Ty for info, I didn't notice that . Code updated :)
+ 1
Ratnapal Shende very nice solution! Wish I could double upvote this 👍
+ 1
Coding Cat [Mouse searching] Thank you so much! ☺️🎊
- 4
Ndkeodjrrneodo