The Fix
You're just one line off. It should be:
def initials(phrase):
words = phrase.split()
result = ""
for word in words:
result += word[0] # correction is here
return result.upper()
print(initials("Universal Serial Bus")) # Should be: USB
print(initials("local area network")) # Should be: LAN
print(initials("Operating system")) # Should be: OS
Explanation
word is an individual word from your string of words (i.e. "Universal" from "Universal Serial Bus"). The first index ([0]) is the first letter that you're looking for (i.e. "U" out of "Universal").
words[word][0] translates to something like "Universal Serial Bus"[Universal][0], which is why you're getting the error (what is the "Universal" index of something haha). word[0] on the other hand translates to something like "Universal"[0].
Additional Explanation
The functionality like I think what you're expecting would be:
def initials(phrase):
words = phrase.split()
result = ""
for word in range(len(words)):
result += words[word][0]
return result.upper()
In your example and my initial solution word is a string pulled from the list of words (i.e. 'Universal' from ['Universal', 'Serial', 'Bus']). From how you wrote your code I think you may be expecting word to work more like an index (i.e. words is a list of indices [0, 1, 2] that the for loop iterates through, and word would be the index of each individual word. Both solutions work and are valid but the first is arguably more "pythonic."
wordis already each successive item inwords. You don't need to refer towordsagain. Just useresult += word[0]