Answer to Question #200103 in Python for sudheer

Question #200103

str_user = input('Enter your string: ')

# ord('A') = 65 ord('Z') =90

print (*[ord(i.upper())-64 for i in str_user if 65<= ord(i.upper()) <= 90],sep='-')

if we give space between two words it is printing "-"

if we give "sudheer kumar" it should print 19-21-4-8-5-5-18 11-21-13-1-18 like this.

but it is printing like this 19-21-4-8-5-5-18-11-21-13-1-18 with no space


1
Expert's answer
2021-05-30T07:21:13-0400
str_user = input('Enter your string: ')


for i in str_user:
    n=ord(i.upper())
    if 65<= n <= 90:
        print(n-64,end="-")
    if i==" ":
        print("  ",end="")
        

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