- 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

# Python Program to Count number of binary strings without consecutive 1’

In this article, we will learn about the solution to the problem statement given below.

**Problem statement** − We are given a positive integer N, we need to count all possible distinct binary strings available with length N such that no consecutive 1’s exist in the string.

Now let’s observe the solution in the implementation below −

## Example

# count the number of strings def countStrings(n): a=[0 for i in range(n)] b=[0 for i in range(n)] a[0] = b[0] = 1 for i in range(1,n): a[i] = a[i-1] + b[i-1] b[i] = a[i-1] return a[n-1] + b[n-1] # main n=5 print("The number of strings: ",countStrings(n))

## Output

The number of strings: 13

All the variables are declared in the local scope and their references are seen in the figure above.

## Conclusion

In this article, we have learned about how we can make a Python Program to Count number of binary strings without consecutive 1’

- Related Articles
- C/C++ Program to Count number of binary strings without consecutive 1’s?
- Program to Count number of binary strings without consecutive 1’s in C/C++?
- Count number of binary strings without consecutive 1's in C
- Count Binary String without Consecutive 1's
- Program to count the number of consistent strings in Python
- Python program to check if there are K consecutive 1’s in a binary number?
- Program to find longest consecutive run of 1 in binary form of a number in C++
- Program to count number of ways to win at most k consecutive games in Python
- Program to find concatenation of consecutive binary numbers in Python
- Python program to count pairs for consecutive elements
- Program to count number of square submatrices in given binary matrix in Python
- Count number of binary strings of length N having only 0’s and 1’s in C++
- C# program to check if there are K consecutive 1’s in a binary number
- Python program to count the pairs of reverse strings
- Program to count number of strings we can make using grammar rules in Python

Advertisements