-
-
Save RabeyaMuna/8778b0a731ec6894cb6432dc6a14603a to your computer and use it in GitHub Desktop.
def initials(phrase): | |
words = phrase.split() | |
result = "" | |
for word in words: | |
x=list(word) | |
if x[0].isupper(): | |
result +=x[0] | |
elif x[0].islower(): | |
result +=x[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 |
#Code by rahul sehrawat
def initials(phrase):
words = phrase.split()
result = ""
for word in words:
result += word[0].upper()
return result
def initials(phrase):
words = phrase.split()
result = ""
for word in words:
result += word[0]
return result.upper()
def initials(phrase):
words = phrase.split()
result = ""
#print(phrase)
#print(words)
for word in words:
result += word[0].upper()
return result
i have a doubt..
how word[0]=USB
if words=universal serial bus
if we ran loop for word in words then it should give only U
hey @Rajshiikhar1691999 thats because u use split function so the word is broken dowwn further after which index is taken hence u get usb instead of u
` 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
Here is output:
USB
LAN
OS
`
`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`