maths.special_numbers.happy_number

Functions

is_happy_number(→ bool)

A happy number is a number which eventually reaches 1 when replaced by the sum of

Module Contents

maths.special_numbers.happy_number.is_happy_number(number: int) bool

A happy number is a number which eventually reaches 1 when replaced by the sum of the square of each digit.

Parameters:

number – The number to check for happiness.

Returns:

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