human
Write me a the Python program you requested given the following:
Solve in Python:
Count the number of segments in a string, where a segment is defined to be a contiguous sequence of non-space characters.

Please note that the string does not contain any non-printable characters.

Example:

Input: "Hello, my name is John"
Output: 5
assistant
#Here is the Python program you requested.

class Solution:
     def countSegments(self, s):
         """
         :type s: str
         :rtype: int
         """
         if len(s)==0:
             return 0
         seen_character = False
         count = 0
         for char in s:
             if seen_character and char == ' ':
                 count += 1
                 seen_character = False
             elif seen_character == False and char != " ":
                 seen_character = True
         if seen_character:
             count += 1
         return count