Check whether a number has consecutive 0’s in Python

Share on facebook
Share on twitter
Share on linkedin
Share on twitter
Share on tumblr

In this Python Program, we will check if the given number has consecutive 0’s .

Python Program to check whether a number has a consecutive 0’s

#codeatglance python program 
def result(N, K): 
z = toK(N, K) 
if (check(z)): 
print("Yes") 
else: 
print("No") 
def toK(N, K): 
 # Weight of each digit 
 w = 1
 s = 0
 while (N != 0): 
 r = N % K 
 N = N//K 
 s = r * w + s 
 w* = 10
 return s 

def check(N): 
 fl = False
 while (N != 0): 
 r = N % 10
 N = N//10
 if (fl == True and r == 0): 
 return False
 if (r > 0): 
 fl = False
 continue
 fl = True
 return True
N, K = 15, 8
result(N, K) 

Output: Yes

Leave a Comment

Your email address will not be published. Required fields are marked *