1010101
10101
101
1
I want to recreate this pattern using Python. I am a beginner and tried many times but didn't find the answer.
1010101
10101
101
1
I want to recreate this pattern using Python. I am a beginner and tried many times but didn't find the answer.
I see your a python beginner. Here is the code to produce a inverted triangle as it is a little complex.
rows = int(input("Enter number of rows: "))
for i in range(rows, 1, -1):
for space in range(0, rows-i):
print(" ", end="")
for j in range(i, 2*i-1):
print("1 ", end="")
for j in range(1, i-1):
print("1 ", end="")
print()
This should be a bit of a hint for you to work through. now try and solve how to use the repeating 1 and 0
# number of 0/1 in first line. change to any uneven number (7, 19, 217,...)
n = 7
for i in range(n, 0, -2):
print(" " * int((n - i) / 2), "".join(str(j % 2) for j in range(1, i+1, 1)))
output:
1010101
10101
101
1