Advertisement
makispaiktis

Abbreviate a 2-Word Name (Codewars)

Oct 31st, 2019 (edited)
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. '''
  2.  
  3.  
  4. Write a function to convert a name into initials. This kata strictly takes two words with one space in between them.
  5.  
  6. The output should be two capital letters with a dot seperating them.
  7.  
  8. It should look like this:
  9.  
  10. Sam Harris => S.H
  11.  
  12. Patrick Feeney => P.F
  13.  
  14. '''
  15. def abbreviateName(name):
  16.     firstLetter = name[0]
  17.     indexOfSpace = -1000
  18.     for i in range(0, len(name)):
  19.         if name[i] == ' ':
  20.             indexOfSpace = i
  21.  
  22.     secondLetter = name[indexOfSpace+1]
  23.     return (firstLetter.upper() + "." + secondLetter.upper())
  24.  
  25. # MAIN FUNCTION
  26. name = input("Give me a name: ")
  27. print(abbreviateName(name))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement