50 XP

23. Initials

Intermediate strings

Write a function initials(name) that takes a person's name and returns its initials as a string: the first letter of each word, as a capital, followed by a dot. Don't put spaces between them.

Every word counts, short ones too: Guido van Rossum gives G.V.R.. Words can be separated by more than one space, with spaces at the start or end; those don't change the answer. If name is empty, return an empty string "".

Example 1

Inputname = "ada lovelace"
Output"A.L."
Explanationa and l, as capitals, each with a dot.

Example 2

Inputname = "Guido van Rossum"
Output"G.V.R."
Explanation"van" is a word too, so its v counts.

Example 3

Inputname = " margaret hamilton "
Output"M.H."
ExplanationThe extra spaces don't change anything.

Constraints

  • name has 0 to 100 characters.
  • It holds only letters and spaces.

Submit also runs 3 more tests you can't see.

Practises String Methods (lesson 5).

Code
def initials(name):
    """Turn a name into its initials, like "A.L.".

    name: str, words separated by spaces; may be empty
    Returns: str, each word's first letter as a capital,
        followed by a dot
    """
    # Write your code here
    pass