【问题标题】:Write a python script that generates an acronym word from a given sentence编写一个 python 脚本,根据给定的句子生成首字母缩略词
【发布时间】:2022-12-20 15:13:11
【问题描述】:

基本上我们必须制作一个首字母缩写词,我们必须从长句中生成短句。

我尝试运行代码,但在从输入中获取字符串时显示错误。

【问题讨论】:

  • 请向我们展示您的代码!
  • 错误是什么?

标签: python string function input acronym


【解决方案1】:

创建首字母缩略词的函数

def fxn(stng): # 添加第一个字母 oupt = stng[0]

# iterate over string
for i in range(1, len(stng)):
    if stng[i - 1] == ' ':
        # add letter next to space
        oupt += stng[i]

# uppercase oupt
oupt = oupt.upper()
return oupt

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-21
    • 2011-01-08
    相关资源
    最近更新 更多