a happy number is a number which eventually reaches 1 when replaced by the sum of the square of each digit param number the number to check for happiness return true if the number is a happy number false otherwise ishappynumber19 true ishappynumber2 false ishappynumber23 true ishappynumber1 true ishappynumber0 traceback most recent call last valueerror number0 must be a positive integer ishappynumber19 traceback most recent call last valueerror number19 must be a positive integer ishappynumber19 1 traceback most recent call last valueerror number19 1 must be a positive integer ishappynumberhappy traceback most recent call last valueerror number happy must be a positive integer a happy number is a number which eventually reaches 1 when replaced by the sum of the square of each digit param number the number to check for happiness return true if the number is a happy number false otherwise is_happy_number 19 true is_happy_number 2 false is_happy_number 23 true is_happy_number 1 true is_happy_number 0 traceback most recent call last valueerror number 0 must be a positive integer is_happy_number 19 traceback most recent call last valueerror number 19 must be a positive integer is_happy_number 19 1 traceback most recent call last valueerror number 19 1 must be a positive integer is_happy_number happy traceback most recent call last valueerror number happy must be a positive integer
def is_happy_number(number: int) -> bool:
    
    if not isinstance(number, int) or number <= 0:
        msg = f"{number=} must be a positive integer"
        raise ValueError(msg)

    seen = set()
    while number != 1 and number not in seen:
        seen.add(number)
        number = sum(int(digit) ** 2 for digit in str(number))
    return number == 1


if __name__ == "__main__":
    import doctest

    doctest.testmod()