Python零基础学习代码实践 —— 提取字符串里面的单词数


str = input()
str1 = str.strip()
index = 0
count = 0
while index < len(str1):
    while str1[index] != " ":
        index += 1
        if index == len(str1):
            break
    count += 1
    if index == len(str1):
        break
    while str1[index] == " ":
        index += 1
print(count)


执行结果

C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\python.exe C:/Users/Administrator/PycharmProjects/untitled/day005/提取字符转里面的单词数.py

4

Process finished with exit code 0


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章