Unable to figure out the output for other values of N

I am unable to understand the output for different values of N apart from N=5. Could you please provide and explain the output for N=6 and N=7 as well?

The spaces variable is hardcoded as 4 and should be adjusted based on N .

You can refer my code as well

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.