小编syl*_*let的帖子

python字符串循环中输出错误

我在python(2.7)上有一个赋值,让我得到一个字符串的输出.在第4个问题中,要求提供早先出现的字母表.这个测试只是句子每个单词的第一个字符.示例:"这是一个句子",结果应为"a",因为它是字母表的第一个字母.

这是我的代码(包括以前的作业问题)

def GetNumWords ( Sentence ):
    Count = 0
    Length = len( Sentence )
    Index = 0
    while Index < Length:
        Char = Sentence [ Index ]
        if Char != ' ':
            Count += 1
            while Char != ' ' and Index < Length:
                Char = Sentence [ Index ]
                Index += 1
        else:
            Index += 1
    return Count

def GetWordNum ( Sentence, WordNum ):
    Count = 0
    Length = len( Sentence )
    Index = 0
    Word = '' …
Run Code Online (Sandbox Code Playgroud)

python string

4
推荐指数
1
解决办法
127
查看次数

标签 统计

python ×1

string ×1