String manipulaiton runtime error python -


input: 3

gandhi mahatma gandhi mohndas karamchand gandhi 

output:

gandhi  m. gandhi  m. k. gandhi  

and wrote following code:

n =  int(input())   while n > 0  :   k = raw_input()    if k.find(" ") != -1:      final = str(k[0].upper() + '.')       in range(len(k)) :       if (k[i] == ' ') & (k[i:].find(" ")):         final += k[i+1].upper() + ". "       else:           if(k[i] == ' '):             final += k[i+1].upper() + k[i+2:].lower()       n -= 1      print final[0:len(final)]   else :     print  k[0].upper() + k[1:].lower() 

i'm getting runtime error this. can explain why? ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­

try code.

str = "gandhi mahatma gandhi mohndas karamchand gandhi" temp = '' st in str.split():     if st == 'gandhi':         temp = temp + ' ' + st.title()     else:         temp = temp + ' ' + st[0].upper() + '.' print temp 

output per expectation - gandhi m. gandhi m. k. gandhi


Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -