Computer Science, asked by jownjenga625, 7 months ago

Fill in the gaps in the initials function so that it returns the initials of the words contained in the phrase received, in upper case. For example: "Universal Serial Bus" should return "USB"; "local area network" should return "LAN”. def initials(phrase): words = phrase.upper result = "" for word in words: result += words return result print(initials("Universal Serial Bus")) # Should be: USB print(initials("local area network")) # Should be: LAN print(initials("Operating system")) # Should be: OS

Answers

Answered by SreeathK4587
33

Answer:

def initials(phrase):

   words = phrase.split()

   result = ""

   for word in words:

       result += word[0].upper()

   return result

Explanation:

For a long name, we need to split it into separate elements to gets its first letter. The different words in phrase variable is splitted and is stored in words variable. Then for every word in words, we take the first letter(index starts from 0 in python) and changes it to upper case.

Similar questions