code: def calculate_parity(n):
      
      if not is_natural(n):
          raise ValueError('Expected n to be a positive integer.')
  
      y = 0
      n = abs(n)
      while n:
          y += n & 1
          n = n >> 1
      return y & 1
docs: Calculates and returns the parity of a number.
  
      The parity of a number is ``1`` if the number has an odd number of ones
      in its binary representation, otherwise ``0``.
  
      Args:
        n (int): the number whose parity to calculate
  
      Returns:
        ``1`` if the number has an odd number of ones, otherwise ``0``.
  
      Raises:
        ValueError: if ``n`` is less than ``0``.