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
a b c d e f g h i j
1 2 3 4 5 6 7 8 9 10
k l m n o p q r
11 12 13 14 15 16 17 18
s t u v w x y z
19 20 21 22 23 24 25 26
Input
The input will be a string in the single line containing spaces and letters (both uppercase and lowercase).
Output
The output should be a single line containing the secret message. All characters in the output should be in lower case.
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
Sample Input 2
Foundations
Sample Output 2
6-15-21-14-4-1-20-9-15-14-19
alphabet = {"a":1,"b":2,"c":3,"d":4,"e":5,"f":6,"g":7,"h":8,"i":9,"j":10,"k":11,"l":12,"m":13, "n":14, "o":15, "p":16, "q":17, "r":18, "s":19, "t":20, "u":21, "v":22,"w":23,"x":24, "y":25, "z":26}
inp = input("Enter a string: ")
for char in inp:
if char == " ":
print(char,"-", end="", sep="")
elif char == inp[-1]:
print(alphabet[char.lower()], end="", sep="")
else:
print(alphabet[char.lower()],"-", end="", sep="")
Comments
Leave a comment