Page 22 - 2501_KVS_C-6
P. 22
Aryan: I did it... I did it! I am so happy. I am learning without any problem.. Initially I thought
coding will be tough but actually it is not if you understand the concept well..Look at my code
and the hexagon that I created.
Gowri: Instead of writing the same commands six times, you can use a for loop.
A for loop is used for repetitive execution of code—so if you need to repeat certain commands
again and again, you can simply place them inside a loop.
For example:
Ø
for i in range(6):
pen.forward(100)
pen.left(60)
It will also produce the same result of making the hexagon.
Ø
Where, range(n) is a library function which takes a no. which actually means the
Ø
total steps for which a command/commands are to be repeated. When I gave 6
it means total six steps/times ( starting from 0 to 5, both inclusive)
1.6 DRAWING CIRCLE AND DOT
We can also draw circle in Python turtle by using pen.circle(r), here r means the radius of
the circle. Radius is taken as the total pixels/points starting from home position of the pen
(turtle).
Gowri: Would you like to make a circle with radius 50 points.
Aryan: OK ..I will..
Look Gowri..I am done with this shape too.
Gowri: You can also create a filled circle by just changing circle with dot..e.g. pen.dot(50). It
will look something like this:
20 KVS DELHI REGION 2025

