Answer to Question #200337 in Python for sudheer

Question #200337

inputLine = input()

letters = "abcdefghijklmnopqrstuvwxyz"

secreMessage=""

for l in inputLine:

    indexLetter=letters.find(l.lower())

    if(indexLetter!=-1):

        indexLetter+=1

        secreMessage+=str(indexLetter)+"-"

    else:

        secreMessage+=l

print(secreMessage[:-1])

if we give input"sudheer kumar" it should print "s-u-d-h-e-e-r k-u-m-a-r" like this

but it is printing "s-u-d-h-e-e-r- k-u-m-a-r" like this

so can anyone please give correct code?


1
Expert's answer
2021-05-31T05:39:46-0400

Here is the corrected code:

val = input('Enter name: ')

x = list(val)

answer = ''

for n in x:

  answer = answer + str(n) + '-' 

z = list(answer)

i1 = z.index(' ')

z.pop(i1+1)

z.pop(i1-1)

z.pop()

s = ''.join(z)

print(s)


Here is the result screen:







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