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 '-'.
input:
python learning
expected output: 16-25-20-8-15-14 12-5-1-18-14-9-14-7
your output: 16-25-20-8-15-14- 12-5-1-18-14-9-14-7
there is is extra " - " after 14 please rectify it !!!
str_user = input('Enter your string: ')
print()
s=str_user.split(" ")
for i in s:
for r in range(len(i)):
n=ord(i[r].upper())
if 65<= n <= 90:
if r==len(i)-1:
print(n-64,end=" ")
else:
print(n-64,end="-")
Output
Comments
Leave a comment