美文网首页
c05ex09.py

c05ex09.py

作者: 特丽斯纳普 | 来源:发表于2018-03-30 20:32 被阅读0次
# c05ex09.py
#    Count words in sentence


def main():
    print("Word counter")
    print()

    phrase = input("Enter a phrase: ")

    # using accumulator loop
    count = 0
    for i in phrase.split():
        count = count + 1

    # alternatives: count = len(phrase.split())
    #               count = phrase.count(" ") + 1

    print("Number of words:", count)

main()

相关文章

网友评论

      本文标题:c05ex09.py

      本文链接:https://www.haomeiwen.com/subject/tqqwcftx.html