Python Program to Print 1-10-101-1010 Number Pattern
Question: write a program in Python to generate a 1-10-101-1010 binary number pattern up to n lines, where n is given by the user.
Python Source Code: 1-10-101-1010 Pattern
# Program to print 1-10-101-1010
n = int(input("Enter number of lines of pattern: "))
for i in range(1,n+1):
for j in range(1, i+1):
print(j%2, end="")
print()
The output of the above program is:
Enter number of lines of pattern: 14 1 10 101 1010 10101 101010 1010101 10101010 101010101 1010101010 10101010101 101010101010 1010101010101 10101010101010