【发布时间】:2022-12-20 15:13:11
【问题描述】:
基本上我们必须制作一个首字母缩写词,我们必须从长句中生成短句。
我尝试运行代码,但在从输入中获取字符串时显示错误。
【问题讨论】:
-
请向我们展示您的代码!
-
错误是什么?
标签: python string function input acronym
基本上我们必须制作一个首字母缩写词,我们必须从长句中生成短句。
我尝试运行代码,但在从输入中获取字符串时显示错误。
【问题讨论】:
标签: python string function input acronym
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
【讨论】: