“”"
统计单词个数
“”"
def countWorld(s):
n = len(s)
count = 0
for i in range(n):
if s[i] != " " and (i == 0 or s[i-1] == " "):
count += 1
return count
if __name__ == "__main__":
s = "hi, you are very good!"
print(countWorld(s))
“”"
统计单词个数
“”"
def countWorld(s):
n = len(s)
count = 0
for i in range(n):
if s[i] != " " and (i == 0 or s[i-1] == " "):
count += 1
return count
if __name__ == "__main__":
s = "hi, you are very good!"
print(countWorld(s))