
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Check whether a number has consecutive 0’s in the given base or not using Python
When it is required to check if a number has consecutive zeroes of a specific base, a method is defined, that takes the number and base as parameters, and uses another method to return Yes or No depending on whether the base is present or not.
Below is a demonstration of the same −
Example
def check_consecutive_zero(N, K): my_result = convert_to_base(N, K) if (check_n(my_result)): print("Yes") else: print("No") def convert_to_base(N, K): weight = 1 s = 0 while (N != 0): r = N % K N = N//K s = r * weight + s weight*= 10 return s def check_n(N): res = False while (N != 0): r = N % 10 N = N//10 if (res == True and r == 0): return False if (r > 0): res = False continue res = True return True N, K = 8, 2 print("Does the number have consecutive zeroes in the base ?") check_consecutive_zero(N, K)
Output
Does the number have consecutive zeroes in the base ? No
Explanation
A method named ‘check_consecutive_zero’ is defined that takes the number and base.
The ‘convert_to_base’ method is used to convert the given number to a specific base.
Depending on whether the output is of a specific base, Yes or No is returned.
The ‘check_n’ method is used to check if the number is 0.
The value for N and K are defined.
The ‘check_consecutive_zero’ method is called by passing N and K.
The output is displayed on the console.
- Related Articles
- Check whether the given number is Euclid Number or not in Python
- Check whether the given number is Wagstaff prime or not in Python
- Program to check whether given number is Narcissistic number or not in Python
- Check whether a given number is Polydivisible or Not
- How to check whether a number is prime or not using Python?
- Check if a number is in given base or not in C++
- Program to check whether the given number is Buzz Number or not in C++
- Python Pandas - Check whether the DateOffset value has been normalized or not
- Python Pandas - Check whether the BusinessDay Offset has been normalized or not
- Python Pandas - Check whether the BusinessHour Offset has been normalized or not
- Python Pandas - Check whether the CustomBusinessDay Offset has been normalized or not
- Python Pandas - Check whether the CustomBusinessHour Offset has been normalized or not
- Check whether the given numbers are Cousin prime or not in Python
- Check whether N is a Dihedral Prime Number or not in Python
- Check if the given number is Ore number or not in Python

Advertisements