From the course: Python Practice: Real-World Coding Challenges

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Solution: It's hip to be square

Solution: It's hip to be square

(pleasant electronic music) - [Instructor] It's hip to be square. For this solution, I added a function to the terminal scribe class called drawSquare. It takes in as an argument the size of the square. Then it's just a matter of looping through that many times as you draw each side of the square, so I have these four while loops with a variable called i that starts at zero and increments by one in each pass through the loop. I start by going right then down then left and then up again to complete the square. Then outside the class at the bottom, I call this width scribe.drawSquare down here, and I've passed in the number 20, so it should draw a square with 20 units on each side. Let's go try it out.

Contents