Program to print a right angled triangle using alternate rows of zeros and ones in Python
In the python programming article, we are going to learn
program to print a right angled triangle using alternate rows of zeros and ones in python
Program to print a right angled triangle using alternate rows of zeros and ones
The program is as follows:
# Owner : TutorialsInhand Author : Devjeet Roy
size = int(input("Enter the no of rows: "))
for i in range(1,size+1):
for j in range(i):
if i % 2 == 0:
print(0, end=" ")
The output of the program is as follows:
PS C:\Users\DEVJEET\Desktop\tutorialsInHand> python code.py
Enter the no of rows: 7
0 0 0
1 1 1 1
0 0 0 0 0
1 1 1 1 1 1
0 0 0 0 0 0 0
Few important tips about the program
1. First we ask the user to enter the number of rows of the pattern.
2. Then we use nested loops to print the pattern. The nested loops take care of the rows and columns respectively.
3. The variable i is the judges whether 1 should be printed or 0.
4. We use the blank print() statement to get the control to the next line.
Would you like to see your article here on tutorialsinhand.
program by tutorialsinhand.com
About the Author
Full Stack Web Developer & Blockchain Enthusiast
Page Views :
Published Date :