Hiranandani Foundation School International
2024-2025
SUBJECT: Computing UNIT NAME- Computational GRADE– VII 5 December,2024
thinking- Python -turtle library
STUDENT`S NAME: DIV: Worksheet No.- 19
Link to test python turtle code
[Link]
Basic Turtle Commands
Here are some basic commands to control a turtle in Python's Turtle graphics module:
❖ Movement:
➢ forward(distance): Moves the turtle forward by the specified distance.
➢ backward(distance): Moves the turtle backward by the specified
distance.
➢ right(angle): Turns the turtle 1 right by the specified angle in degrees.
➢ left(angle): Turns the turtle left by the specified angle in degrees.
❖ Pen Control:
➢ penup(): Lifts the pen, so the turtle doesn't draw while moving.
➢ pendown(): Lowers the pen, so the turtle starts drawing again.
➢ pensize(width): Sets the width of the pen.
➢ pencolor(color): Sets the color of the pen.
➢ speed(speed): Sets the speed of the turtle's movements.
❖ Shape and Fill:
➢ shape(shape): Sets the shape of the turtle (e.g., "turtle", "arrow", "circle").
➢ fillcolor(color): Sets the fill color.
➢ begin_fill() and end_fill(): Starts and ends filling a shape.
1 | Page
Example of using above commands
#Draw a square #Draw color filled square
import turtle import turtle
# Set up the screen screen = [Link]()
screen = [Link]() [Link]("white")
[Link]("white")
pen = [Link]()
# Create a turtle object [Link]("red")
pen = [Link]()
pen.begin_fill()
# Loop to draw the square
for i in range(4):
for i in range(4): [Link](100)
[Link](100) [Link](90)
[Link](90)
pen.end_fill()
# Finish drawing 1q
[Link]() [Link]()
Exercise
1. Draw a Triangle
Modify the program to draw a triangle with three sides, each of length 100 units.
2. Draw a Circle
Write a program that uses Turtle to draw a circle with a radius of 50 units.
3. Draw Multiple Squares
Write a program that draws 4 squares in a row. Each square should be drawn at a 90-degree
angle from the previous one, and the size of each square should decrease by 20 units.
4. Draw a Pentagon
Create a Python program to draw a regular pentagon with each side of length 80 units.
2 | Page