Python Forum
Need help with understanding for/while loops!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with understanding for/while loops!
#3
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
Reply


Messages In This Thread
RE: Need help with understanding for/while loops! - by ThiefOfTime - Sep-26-2018, 11:46 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Fundamental understanding-problem regards to while-loops Placebo 7 3,978 Oct-11-2018, 01:18 PM
Last Post: Placebo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020