day 26 Number's Square

Updated: Getting the length of the maximum elem that we will be printing so adjusting the spacing according to that elem.

def buzz(): ipnut=int(input()) if(ipnut==0): print() a,b=0,0 c,d=a,b count=1 # answer=[[0]*ipnut]*ipnut answer=[[0 for j in range(ipnut)] for i in range(ipnut)] while(b<ipnut): a=0 answer[a][b]=count # print(f"Update 0: {a},{b} with: {count}") count+=1 c=a+1 d=b-1 while(d>=0): answer[c][d]=count # print(f"Update 1: {c},{d}, with {count}") count+=1 c+=1 d-=1 b+=1 a+=1 b-=1 # Get the max elem's length for spacing l_m=len(str(ipnut*ipnut))+1 while(a<ipnut): answer[a][b]=count count+=1 c=a+1 d=b-1 while(c<ipnut): answer[c][d]=count count+=1 c+=1 d-=1 a+=1 for ls in answer: for el in ls: # Using l_m for getting that much amount of space print(f"{el:>{l_m}}",end=" ") print() # print(*ls,sep=" ") buzz()

Comments

Popular Posts