Skip to content

Instantly share code, notes, and snippets.

@ayubmetah
Created January 16, 2021 08:15
Show Gist options
  • Save ayubmetah/02848a06df802d411a38261aee6c6158 to your computer and use it in GitHub Desktop.
Save ayubmetah/02848a06df802d411a38261aee6c6158 to your computer and use it in GitHub Desktop.
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.split()
result = ""
for word in words:
result += word[0].upper()
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
@AarenCodes
Copy link

Thank you!

@rashadBenSaid
Copy link

Hi
can anyone explain for me line 3 and 5 please ?

@NMNzamu
Copy link

NMNzamu commented Jun 2, 2022

in line 3, the result variable has been created
in line 5, result is in a loop to capitalize every first letter

@rubycarefree
Copy link

My explanation; def a function that could capitalize the first character of a phrase. First, split the phase which is made of words. Then, create a new string variable that is of empty text content. And for each character(word) in the phase, the content will turn the location of 0 into Upper fonts from the empty range.

@AbdulMunim343
Copy link

thank you so much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment