填写缩写函数中的空白,以便它返回收到的短语中包含的单词的缩写(大写)

发布于 2025-01-11 22:18:46 字数 336 浏览 0 评论 0原文

#原始代码

def initials(phrase):
    words = phrase.___
    result = ""
    for word in words:
            result += ___
    return ___
    
print(initials("Universal Serial Bus")) # Should be: USB
print(initials("local area network")) # Should be: LAN
    
print(initials("Operating system")) # Should be: OS

#original code

def initials(phrase):
    words = phrase.___
    result = ""
    for word in words:
            result += ___
    return ___
    
print(initials("Universal Serial Bus")) # Should be: USB
print(initials("local area network")) # Should be: LAN
    
print(initials("Operating system")) # Should be: OS

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

迷荒 2025-01-18 22:18:46

下次请把你遇到的一些代码和遇到的问题贴出来。

def initials(phrase):
    return ''.join(word[0].upper() for word in phrase.split())


print(initials('Universal Serial Bus'))
print(initials('local area network'))
print(initials('Operating system'))

Please next time put some of your code that you are struggling with and problems you encountered.

def initials(phrase):
    return ''.join(word[0].upper() for word in phrase.split())


print(initials('Universal Serial Bus'))
print(initials('local area network'))
print(initials('Operating system'))
凡间太子 2025-01-18 22:18:46
def initials(phrase):
    words = phrase.split()                #splits given data into list  
    result = ""
    for word in words:                    #iterates word in 'words'
        result += word[0].upper()         #stores 1st letter in Uppercase
    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
def initials(phrase):
    words = phrase.split()                #splits given data into list  
    result = ""
    for word in words:                    #iterates word in 'words'
        result += word[0].upper()         #stores 1st letter in Uppercase
    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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文