def fan(s): count = 0 for i in range(len(s)): if s[i] != ' ' and (i == 0 or s[i-1] == ' '): count += 1 return count
编写函数fan,实现功能:统计一行字符串中单词个数,作为函数值返回。字符串在主函数中输入,规定所有单词有小写字母组成,单词之间有若干个空格隔开,一行的开始没有空格。...
最新推荐文章于 2023-10-28 16:59:23 发布
def fan(s): count = 0 for i in range(len(s)): if s[i] != ' ' and (i == 0 or s[i-1] == ' '): count += 1 return count