1
010
10101
0101010
print this using python
I have tried
def print_pattern(rows):
for i in range(rows):
start_char = '1' if i % 2 == 0 else '0'
pattern = ''.join(start_char if j % 2 == 0 else ('0' if start_char == '1' else '1') for j in range(i + 1))
print(pattern)
number_of_rows = 4
print_pattern(number_of_rows)
New contributor
SHIVANSHU SHUKLA is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.