Answer to Question #206047 in Python for Ayushi

Question #206047

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 !!!



1
Expert's answer
2021-06-11T17:12:15-0400
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

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS