Python Program to Print 1-101-10101 Binary Number Pyramid Pattern
Question: write a program in Python to generate a 1-101-10101 binary number pyramid pattern up to n lines, where n is given by the user.
Python Source Code: 1-101-10101 Pattern
# Program to print 1-101-10101
n = int(input("Enter number of lines of pattern: "))
for i in range(1,n+1):
for j in range(1, n-i+1):
print(" ", end="")
for k in range(1,2*i):
print(k%2, end="")
print()
The output of the above program is:
Enter number of lines of pattern: 12 1 101 10101 1010101 101010101 10101010101 1010101010101 101010101010101 10101010101010101 1010101010101010101 101010101010101010101 10101010101010101010101