class Solution: #参数s:字符串 #返回整数 def countSegments(self,s): res = 0 for i in range(len(s)): if s[i] != ' ' and (i == 0 or s[i - 1] == ' '): res += 1 return res#主函数if __name__ == '__main__': s = Solution() n = "If you are right, you don't need to lose your temper" print("输入:",n) print("输出:",s.countSegments(n))