Secret Message - 2
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
Input
The input will be a string in the single line containing spaces and letters.
Output
The output should be a single line containing the secret message. All characters in the output should be in lower case.
Explanation
For example, if the given input is "python", "p" should replaced with "16", similarly "y" with "25","t" with "20","h" with "8","o" with "15","n" with "14". So the output should be "16-25-20-8-15-14".
Sample Input 1
python
Sample Output 1
16-25-20-8-15-14
def main():
s1 = input("Enter string: ")
s2=""
for alphabet in s1:
num=getNum(alphabet)
if(num!=-1):
s2+=str(num)+"-"
else:
s2+=alphabet
print(s2[:-1])
def getNum(alphabet):
letters = "abcdefghijklmnopqrstuvwxyz"
for i in range(0,len(letters)):
if alphabet.islower() and alphabet==letters[i]:
return i+1
if alphabet.isupper() and alphabet==letters[i].upper():
return i+1
return -1
main()
Comments
Leave a comment