Computer Science, asked by anindyaadhikari13, 3 months ago

Python code for this pattern.
1
0 1
0 1 0
1 0 1 0
1 0 1 0 1

Thank you :)​

Answers

Answered by Oreki
10

Code:

k = 1

for i in range(0, 5 + 1):

   for j in range(1, i + 1):

       print("0" if k % 2 == 0 else "1", end="")

       k += 1

   print( )


anindyaadhikari13: c=1
n=int(input("Enter: "))
for i in range(n):
for j in range(i+1):
print(c%2,end=" ")
c+=1
print()
anindyaadhikari13: This is another approach I tried.
anindyaadhikari13: Thanks for your help @Oreki :)
BrainlyProgrammer: Gr8 Answer!!
Oreki: Thanks for the smaller code @anindyaadhikari13!
Oreki: Thanks @swetank232894 too!
Anonymous: Awesome !! ^_^
Oreki: Thanks @CaptainInvictus!
RockingStarPratheek: Appreciable Work Done, Keep it Up
Similar questions