Q:

While loop in python and error ValueError: invalid literal for int() with base 10: ''

I am trying to test if a number is divisible by 11 or not. Here's my code:
def divisible_by_11(s):
    '''Returns True if the number represented by the string s is
    divisible by 11, False otherwise.'''
    p = str(s)
    b = int(str(s)[-1])
    c = int(str(s)[-2])
    total = 0
    motal = 0
    while len(p) > 0:
              a = int(str(s)[:-2])
              b = int(str(s)[-1])
              c = int(str(s)[-2])
              total = total + b
              motal = motal + c
              s = a
              p = str(s)
    return (total-motal) % 11 ==0

But I am getting error
a = int(str(s)[:-2])
ValueError: invalid literal for int() with base 10: ''

Can anyone please help me?
Thanks in advance.

A:

Let's say that s equals 11. So, line
a = int(str(s)[:-2])

will throw an error because str(s)[:-2] will be "" (empty string).
Suggestion: number is divisible with 11 if sum of numbers at odd positions equals sum of numbers at even positions. Knowing this, You can write following function:
def divisible_by_11(s):
    odd_sum = sum([int(x) for x in s[::2]])
    even_sum = sum([int(x) for x in s[1::2]])
    return odd_sum == even_sum

