I am reading ‘Learn Programming with Python part 1’ a Bengali book by Tamim Shahriar Subeen and found an interesting module named Turtle. Now let me share with you a simple code that I just have written.
#Draw a circle using squares import turtle def draw_circle(): turtle.speed(5) turtle.color("yellow") turtle.bgcolor("#2d344c") counter = 0 while counter < 36: for i in range(4): turtle.forward(100) turtle.right(90) turtle.right(10) counter += 1 turtle.exitonclick() draw_circle()
Just save the script in a file and run it, and you will see something like this:
How did I come up with the number 36 in the while loop? (while counter < 36). I just need to figure out a way to rotate the square 10 degrees clockwise each iteration. So it would take 360/10 = 36 iteration to complete the circle.