Given a string, write a program to print a secret message that replaces characters with numbers 'a' with 1, 'b' with 2, ..., 'z' with 26 where characters are separated by '-'.
Note: You need to replace both uppercase and lowercase characters. You can ignore replacing all characters that are not letters.
abcdefghij12345678910
klmnopqr1112131415161718
stuvwxyz1920212223242526
key = 'abcdefghijklmnopqrstuvwxyz'
def shifr(sen:str, key:str):
res = ''
for ch in sen:
if ch == ' ':
res = res[:-1] + ch
continue
if ch.lower() in key:
res += str(key.index(ch.lower()) + 1)
else:
res += ch
res += '-'
return res[:-1]
while True:
print(shifr(input(), key))
Comments
Leave a comment