예제 #1
0
def is_number_balanced(n):
    number = to_digits(n)
    if n >= 0 and n < 10:
        return True
    number_len = len(number)
    if (number_len % 2 == 0):
        const = 0
    else:
        const = 1
    left = sum(number[0:number_len//2])
    right = sum(number[(number_len//2+const):])
    if left == right:
        return True
    else:
        return False
예제 #2
0
def is_number_balanced(n):
    is_balanced = False

    digits = to_digits(n)
    l = len(digits)

    if l == 1:
        is_balanced = True

    elif l % 2 == 0:
        left_s = sum(digits[: l / 2 - 1])
        right_s = sum(digits[l / 2:])

        if left_s == right_s:
            is_balanced = True

    else:
        left_s = sum(digits[: l // 2])
        right_s = sum(digits[l // 2 + 1:])

        if left_s == right_s:
            is_balanced = True

    return is_balanced
예제 #3
0
def is_number_balanced(n):
    is_balanced = False

    digits = to_digits(n)
    l = len(digits)

    if l == 1:
        is_balanced = True

    elif l % 2 == 0:
        left_s = sum(digits[:l / 2 - 1])
        right_s = sum(digits[l / 2:])

        if left_s == right_s:
            is_balanced = True

    else:
        left_s = sum(digits[:l // 2])
        right_s = sum(digits[l // 2 + 1:])

        if left_s == right_s:
            is_balanced = True

    return is_balanced