Given a strong, write a program to print a secret message that replaces character with numbers 'a' with 1, 'b' with 2,...'z' with 26 where characters are separated by '-'
def main(): #Read string inputString = input("Enter string: ") outputString="" for letter in inputString: number=getNumber(letter) if(number!=-1): outputString+=str(number)+"-" else: outputString+=letter print(outputString[:-1])#This function convert letter to numberdef getNumber(letter): alphabet = "abcdefghijklmnopqrstuvwxyz" for i in range(0,len(alphabet)): if letter.islower() and letter==alphabet[i]: return i+1 if letter.isupper() and letter==alphabet[i].upper(): return i+1 return -1main()
Comments
Leave a comment