Sep-26-2018, 11:46 AM
(This post was last modified: Sep-26-2018, 11:47 AM by ThiefOfTime.)
I'm very sorry but the code is very hard to read. Code Tags would help a lot.
The intuitive way to approach that task would be to use two nested while loops. One for the width and one for the height. it is even easier to use while loops and an index for iterating over a list containing all values that has to be placed than using a for loop.
I'm not sure how exactly you want the tips/help, here is my approach to the task:
1. ask the user input (like you did)
2. create a list containing all numbers from left_number to left_number + square_order
3. make one while loop for the number of lines that has to be printed
4. use a variable holding the current_first_number (like 0 in first line, 1 in second line, etc)
5. construct a list by combining a list generated through range(current_first_number, left_number + square_order + 1) and one generated through range(left_number, current_first_number)
6. print that list by joining the contained elements into a string and increase current_first_number
The intuitive way to approach that task would be to use two nested while loops. One for the width and one for the height. it is even easier to use while loops and an index for iterating over a list containing all values that has to be placed than using a for loop.
I'm not sure how exactly you want the tips/help, here is my approach to the task:
1. ask the user input (like you did)
2. create a list containing all numbers from left_number to left_number + square_order
3. make one while loop for the number of lines that has to be printed
4. use a variable holding the current_first_number (like 0 in first line, 1 in second line, etc)
5. construct a list by combining a list generated through range(current_first_number, left_number + square_order + 1) and one generated through range(left_number, current_first_number)
6. print that list by joining the contained elements into a string and increase current_first_number