+ 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

16th Aug 2021, 1:24 PM
Ratnapal Shende
Ratnapal Shende - avatar
5 Antworten
+ 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()
16th Aug 2021, 1:36 PM
Hatsy Rei
Hatsy Rei - avatar
+ 2
Hatsy Rei Thank you so much sir! ☺️ I don't know why I struggle to build logic.. 😢
16th Aug 2021, 4:19 PM
Ratnapal Shende
Ratnapal Shende - avatar
+ 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.
16th Aug 2021, 4:44 PM
Ratnapal Shende
Ratnapal Shende - avatar
+ 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
25th Aug 2021, 8:34 AM
Calvin Thomas
Calvin Thomas - avatar
+ 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
26th Aug 2021, 7:13 AM
Atul [Inactive]