;

Python Program to Print the Binary Number Pattern 1 and 0 in Alternative Rows


Tutorialsrack 16/05/2020 Python

In this Python program, we will learn how to print the binary number pattern 1 and 0 in alternative rows and also print the reversed output the 0 and 1 in alternate rows.

Here is the source code of the program to print the binary number pattern 1 and 0 in alternative rows.

Program 1: Python Program to Print the Binary Number Pattern 1 and 0 in Alternative Rows Using For Loop

Python Program to Print the Binary Number Pattern 1 and 0 in Alternative Rows Using For Loop
# Python Program to Print the Binary Number Pattern 1 and 0 in Alternative Rows
# 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 Rows")  
 
for i in range(1, rows + 1):
    for j in range(1, columns + 1):
        if(i % 2 != 0):          
            print('1', end = '  ')
        else:
            print('0', end = '  ')
    print()
Output

Enter the total Number of Rows: 5

Enter the total Number of Columns: 5

Print Binary Number Pattern 1 and 0 in an alternative Rows

1  1  1  1  1  

0  0  0  0  0  

1  1  1  1  1  

0  0  0  0  0  

1  1  1  1  1

Program 2: Python Program to Print the Binary Number Pattern 1 and 0 in Alternative Rows Using While Loop

Python Program to Print the Binary Number Pattern 1 and 0 in Alternative Rows Using While Loop
# Python Program to Print the Binary Number Pattern 1 and 0 in
# Alternative Rows 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 Rows")

i = 1
while(i <= rows):
    j = 1
    while(j <= columns):
        if(i % 2 != 0):          
            print('1', end = '  ')
        else:
            print('0', end = '  ')
        j = j + 1
    i = i + 1
    print()
Output

Enter the total Number of Rows: 5

Enter the total Number of Columns: 5

Print Binary Number Pattern 1 and 0 in an alternative Rows

1  1  1  1  1  

0  0  0  0  0  

1  1  1  1  1  

0  0  0  0  0  

1  1  1  1  1  

Program 3: Python Program to Print the Binary Number Pattern 1 and 0 in Alternative Rows Without Using If...else

Python Program to Print the Binary Number Pattern 1 and 0 in Alternative Rows Without Using If...else
# Python Program to Print the Binary Number Pattern 1 and 0 in
# Alternative Rows 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 Rows")
 
for i in range(1, rows + 1):
    for j in range(1, columns + 1):
        print('%d' %(i % 2), end = '  ')
    print()
Output

Enter the total Number of Rows: 4

Enter the total Number of Columns: 4

Print Binary Number Pattern 1 and 0 in an alternative Rows

1  1  1  1  

0  0  0  0  

1  1  1  1  

0  0  0  0  

Program 4: If you want to Print first 0 and second 1 then replace the values

If you want to Print first 0 and second 1 then replace the values
# Python Program to Print the Binary Number Pattern 1 and 0 in Alternative Rows
# If you want to Print first 0 and second 1 then replace the values

# 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 Rows")
 
for i in range(1, rows + 1):
    for j in range(1, columns + 1):
        if(i % 2 != 0):          
            print('0', end = '  ')
        else:
            print('1', end = '  ')
    print()
Output

Enter the total Number of Rows: 5

Enter the total Number of Columns: 5

Print Binary Number Pattern 1 and 0 in an alternative Rows

0  0  0  0  0  

1  1  1  1  1  

0  0  0  0  0  

1  1  1  1  1  

0  0  0  0  0 


Related Posts



Comments

Recent Posts
Tags