In this python program, we will learn how to print binary numbers 0 and 1 in alternate columns and also print the reversed output 1 and 0 in alternate columns.
Here is the source code of the program to print binary numbers 0 and 1 in alternate columns.
# Python Program to Print Binary Number 0 and 1 in an Alternative Columns
# Using For Loop
# Take the Input From the User
rows = int(input("Enter the total Number of Rows: "))
columns = int(input("Enter the total Number of Columns: "))
# Print the Output
print("Print Binary Number Pattern 1 and 0 in an alternative Columns")
for i in range(1, rows + 1):
for j in range(1, columns + 1):
if(j % 2 == 0):
print('0', end = ' ')
else:
print('1', end = ' ')
print()
Enter the total Number of Rows: 5
Enter the total Number of Columns: 5
Print Binary Number Pattern 1 and 0 in an alternative Columns
1 0 1 0 1
1 0 1 0 1
1 0 1 0 1
1 0 1 0 1
1 0 1 0 1
# Python Program to Print Binary Number 0 and 1 in an Alternative Columns
# Using While Loop
# Take the Input From the User
rows = int(input("Enter the total Number of Rows: "))
columns = int(input("Enter the total Number of Columns: "))
# Print the Output
print("Print Binary Number Pattern 1 and 0 in an alternative Columns")
i = 1
while(i <= rows):
j = 1
while(j <= columns):
if(j % 2 != 0):
print('1', end = ' ')
else:
print('0', end = ' ')
j = j + 1
i = i + 1
print()
Enter the total Number of Rows: 4
Enter the total Number of Columns: 4
Print Binary Number Pattern 1 and 0 in an alternative Columns
1 0 1 0
1 0 1 0
1 0 1 0
1 0 1 0
# Python Program to Print Binary Number 0 and 1 in an Alternative Columns
# Without Using if...else
# Take the Input From the User
rows = int(input("Enter the total Number of Rows: "))
columns = int(input("Enter the total Number of Columns: "))
# Print The Output
print("Print Binary Number Pattern 1 and 0 in an alternative Columns")
for i in range(1, rows + 1):
for j in range(1, columns + 1):
print('%d' %(j % 2), end = ' ')
print()
Enter the total Number of Rows: 6
Enter the total Number of Columns: 6
Print Binary Number Pattern 1 and 0 in an alternative Columns
1 0 1 0 1 0
1 0 1 0 1 0
1 0 1 0 1 0
1 0 1 0 1 0
1 0 1 0 1 0
1 0 1 0 1 0
# Python Program to Print Binary Number 0 and 1 in an alternative Columns
# Take the Input From the User
rows = int(input("Enter the total Number of Rows: "))
columns = int(input("Enter the total Number of Columns: "))
# Print the Output
print("Print Binary Number Pattern 1 and 0 in an alternative Columns")
for i in range(1, rows + 1):
for j in range(1, columns + 1):
if(j % 2 == 0):
print('1', end = ' ')
else:
print('0', end = ' ')
print()
Enter the total Number of Rows: 5
Enter the total Number of Columns: 5
Print Binary Number Pattern 1 and 0 in an alternative Columns
0 1 0 1 0
0 1 0 1 0
0 1 0 1 0
0 1 0 1 0
0 1 0 1 0
Comments