;

Python Program to Print Box Number Pattern Using Binary Number 0 and 1


Tutorialsrack 16/05/2020 Python

In this Python program, we will learn how to print box number patterns using binary numbers 0 and 1.

Here is the source code of the program to print box number patterns using binary numbers 0 and 1.

Program 1: Python Program to Print Box Number Pattern Using Binary Number 0 and 1 Using For Loop

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

Enter the total Number of Rows: 5

Enter the total Number of Columns: 5

Box Pattern Using Binary Number of 1 and 0

1  1  1  1  1  

1  0  0  0  1  

1  0  0  0  1  

1  0  0  0  1  

1  1  1  1  1 

Program 2: Python Program to Print Box Number Pattern Using Binary Number 0 and 1 and Using While Loop

Python Program to Print Box Number Pattern Using Binary Number 0 and 1 and Using While Loop
# Python Program to Print Box Number Pattern
# Using Binary Number 0 and 1 and 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("Box Pattern Using Binary Number of 1 and 0")

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

Enter the total Number of Rows: 4

Enter the total Number of Columns: 4

Box Pattern Using Binary Number of 1 and 0

1  1  1  1  

1  0  0  1  

1  0  0  1  

1  1  1  1  

Program 3: Replace the Binary Number with 0 to 1 and 1 to 0

Replace the Binary Number with 0 to 1 and 1 to 0
# Python Program to Print Box Number Pattern Using Binary Number 0 and 1
# Replace the Binary Number with 0 to 1 and 1 to 0

# 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("Box Pattern Using Binary Number of 1 and 0")
 
for i in range(1, rows + 1):
    for j in range(1, columns + 1):
        if(i == 1 or i == rows or j == 1 or j == columns):          
            print('0', end = '  ')
        else:
            print('1', end = '  ')
    print()
Output

Enter the total Number of Rows: 5

Enter the total Number of Columns: 5

Box Pattern Using Binary Number of 1 and 0

0  0  0  0  0  

0  1  1  1  0  

0  1  1  1  0  

0  1  1  1  0  

0  0  0  0  0 


Related Posts



Comments

Recent Posts
Tags