-
Notifications
You must be signed in to change notification settings - Fork 0
/
sum_odd_even_digit.py
49 lines (41 loc) · 932 Bytes
/
sum_odd_even_digit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
'''
def divisible_by_11(num):
#your code here
digit=count_digit(num)
even=0
odd=0
for i in range(1 ,digit+1):
if i%2==0:
even+=num//10**(digit-1)
else:
odd+=num//10**(digit-1)
num%=10**(digit-1)
digit-=1
print(even,odd)
return (even-odd)%11==0
def count_digit(num):
remain=num
digit=0
while remain>0:
remain//=10
digit+=1
return digit
'''
def count_digit(num):
remain=num
digit=0
while remain>0:
remain//=10
digit+=1
return digit
def odd_even_difference(num):
digit=count_digit(num)
if digit==1:
return num
elif digit==2:
return (num//10-num%10)
else:
return num//10**(digit-1)-odd_even_difference(num-num//10**(digit-1)*10**(digit-1))
def divisible_by_11(num):
return odd_even_difference(num)%11==0
print(divisible_by_11(121))