+ 1
Please help I am unable to build logic from past 2 hours.
I just wanted to print the pattern like shown below : 100 010 001 # we are not allowed to use any modules or special functions not even if else conditions we need to use just loops to solve this probelm.. but how to build logic on this problem? I am struggling a lot with this matrices problems... please help me to build logic on this program My Attempt : https://code.sololearn.com/cxtfhzLr28Nz/?ref=app
5 Respuestas
+ 8
You are actually very close. There are multiple ways you can achieve this, but I guess you want to do it strictly only via loops?
no_rows=3 # number of rows
for row in range(no_rows):
for one in range(row):
print("0",end="")
print("1",end="")
for i in range(no_rows-1-row):
print("0",end="")
print()
+ 2
Hatsy Rei Thank you so much sir! ☺️
I don't know why I struggle to build logic.. 😢
+ 1
Hatsy Rei
please explain how you think about the logic to use range(no_rows-1-row)
how to visualize it?
how to think like that?
how can I think that I need to minus rows value from no_rows and -1.
how sir how? 😑
in future I want solve my problems myself.. please guide me.
+ 1
How about this one? :-
no_rows = int(input() or 3)
num = 10 ** (no_rows - 1)
for i in range(no_rows):
print(str(num).zfill(no_rows))
num //= 10
+ 1
Ratnapal Shende
no_rows=3 # number of rows
for row in range(no_rows):
for one in range(no_rows):
if row==one:
print("1",end="")
else:
print("0",end="")
print()
#Hope this helps you