0% found this document useful (0 votes)
21 views62 pages

Class 9 - Python Turtle Module

The document outlines the Class IX ICT curriculum focused on Python coding, specifically the Turtle module. It covers key concepts such as importing the Turtle module, window settings, basic motion methods, and pen control methods, along with objectives and activities for students to practice. The curriculum aims to help students understand coding basics, create graphics, and develop problem-solving skills through interactive programming.

Uploaded by

kinley4177
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views62 pages

Class 9 - Python Turtle Module

The document outlines the Class IX ICT curriculum focused on Python coding, specifically the Turtle module. It covers key concepts such as importing the Turtle module, window settings, basic motion methods, and pen control methods, along with objectives and activities for students to practice. The curriculum aims to help students understand coding basics, create graphics, and develop problem-solving skills through interactive programming.

Uploaded by

kinley4177
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 62

PYTHON Key stage IV Class IX

དཔལ་ལྡན་འབྲུག་གཞུང་།
ཤེས་རིག་དང་རིག་རྩལ་གོང་འཕེལ་ལྷན་ཁག།
Department of School Education
Ministry of Education & Skills Development

Python Coding
Class IX ICT Curriculum

January 2024

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Key Concept # 4

TURTLE MODULE

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Concept Overview
Coding Concept Sub-Concepts
● Importing the turtle module
● Turtle window setting - size(), title(), shape(),
bgcolor(), showturtle(), hideturtle()
● Turtle basic motions methods- forward(), backward(),
Python Turtle left(), right(), circle()
Module ● Turtle pen control methods - pencolor(), pensize(),
pendown(), penup(), speed(), goto(), setpos(),
setposition()
● Colour control - begin_fill(), end_fill()
● Text method - write()
January 2024 © ICT Curriculum, MoESD
PYTHON Key stage IV Class IX

Objectives

● Define Python turtle with examples.


● Import the turtle module in Python.
● Manipulate turtle window using setup(), bgcolor(), title() and shape()
methods.
● Use motion methods in turtle programs to control the movement and
create basic shapes.
● Add colours to shapes and drawings using different colour methods.
● Insert text in turtle drawings using text() method.
● Create basic graphics or drawings using the turtle module.

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Introduction to Turtle Module

Turtle is a Python library that is used to create graphics.

The onscreen pen that you use for drawing is called the turtle.

The turtle can draw lines, and shapes and also change colours, sizes and
shapes.

The turtle can also be used to create complex shapes and images using
loops and functions.

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Importance of Turtle Module


Helps beginners understand coding basics like loops
Easy Start
and variables.

See Results You can see what your code does instantly.

Be Creative Make cool drawings and simple games.

Solve Problems Practice thinking logically and finding solutions.

Learn Coordinates Understand how x and y coordinates work.

Try GUIs Get ready for making interactive programs.

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Importing Turtle Module


Before we can use turtle, we need to import it. The following are commonly
used methods to import the turtle module in Python:

1 2
Direct import Import Everything
Using the import turtle Using the from turtle import *
statement - this imports the entire statement - this imports all of the
turtle module and allows you to functions and classes from the turtle
use all of its functions and module into the current namespace, so
classes. you don't have to use the turtle prefix
when calling them.

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Examples of importing Turtle Module


To draw a rectangle we can write the following codes in Python Turtle. In the
first example we use import turtle, and in the second case we use from
turtle import * .

1 2
import turtle from turtle import *
Tk=turtle.Turtle() for x in range(4)
for x in range(4) forward(200)
Tk.forward(200) right(90)
Tk.right(90) done()
Tk.done()

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Turtle Methods
● In Turtle graphics, a virtual turtle moves around the screen, and programmers
can control its movements and drawings using specific methods.
● The turtle can also be configured to change its colour, shape, and size using
various methods.

Turtle Methods

Window setting Basic motions Pen control Colour control Text method

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

ACTIVITIES
1
1. Understanding the Different
Window Settings Methods
WINDOW SETTING 2. Demo - Window Setting
3. Activity 1 - Window Setting

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Turtle Window Settings

Turtles live in a grid world guided by


an x-axis and y-axis. Turtle’s home is
at the very center of the canvas, at
coordinate point (0,0).

In the canva shown alongside the


x-axis goes from -200 to +200 and the
y-axis also goes from -200 to 200.

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Turtle Window Settings


We can apply the following methods to set turtle window.

Sl# Methods Purpose

1 setup(x, y) To set the size of the canva


2 title(" ") To set the windows title

To change the turtle graphics object to one of the


3 shape("turtle")
built-in shapes( "turtle", "arrow", "circle", or "square")

4 bgcolor("color") To change the background color


5 showturtle() To make the turtle cursor visible on screen
6 hideturtle() To make the turtle cursor invisible on screen
January 2024 © ICT Curriculum, MoESD
PYTHON Key stage IV Class IX

Demo - Windows Setting

Write a Python program to change the


turtle window’s settings as follows:
● Set the window size to 300x250
pixels.

● Create a program that changes the


background colour to yellow.
● Give the window title "Colorful
Turtle Canvas."

A sample window is provided alongside.

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Demo - Solution
Code

1 #import the turtle module

2 from turtle import *


3 # Set the background color of the window to yellow
4 bgcolor("yellow")
5 #Set the window size to 300x250 pixels
6 setup(350,250)
7 # Set the title of the Turtle window
8 title("Colorful Turtle Canvas")

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Activity 1 - Windows Setting


Write a Python program to create a turtle
windows with the following settings:
1. Change the shape of the turtle to
“square”.

2. Change the window size height=400


and width=350
3. Change the title to “This is a title to the
window!”.
4. Change the background colour to
“pink”.
January 2024 © ICT Curriculum, MoESD
PYTHON Key stage IV Class IX

Activity 1 - Solution
Code
1 #import the turtle module
2 from turtle import *
3 # Create a Turtle object with the shape "square"
4 shape("square")
5 #Change the window size height=400 and width=350
6 setup(height=400,width=350)
7 # Set the title of the Turtle window
8 title("This is a title to the window!")
9 # Set the background color of the window to pink
10 bgcolor("pink")

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

ACTIVITIES
1. Understanding Turtle Motions
and Motion Methods
2
2. Demo 1 - Drawing a Line
BASIC MOTIONS 3. Activity 1 - Drawing a Circle
4. Demo 2 - Drawing an Arc
5. Activity 2- Drawing a Square
6. Activity 3 - Drawing an Ice Cream

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Turtle Basic Motions


To draw something on the turtle canvas, we need to move the turtle. Following
methods are used to apply motion to the turtle.

Sl# Methods Purpose


1 forward(distance) To move the turtle forward a specified distance.

2 backward(distance) To move the turtle backward a specified distance.

3 right(angle) To turn the turtle 90 degrees to the left.

4 left(angle) To turn the turtle 90 degrees to the right.


5 circle(radius) To draw a circle.

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Example 1 - Turning Left/Right


Write a Python program using the turtle module to turn the turtle left and right.

Code

1 #turtle program to turn the turtle left and then right


2 from turtle import *
3 title(“Turning left and right”)
4 left(90)
5 forward(100)
6 right(90)
7 forward(100

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Demo 1 - Drawing a line


Write a Python program using the turtle module to move 100
pixels forward and then move 100 pixels backward.

Code

1 #turtle program to draw the moving forward and backward


2 from turtle import *
3 title("Moving forward and backward") Output
4 forward(100)
5 backward(100)

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Drawing a Circle
The circle method in Python turtle can be used to draw a circle or an arc.

Syntax → circle(radius, extent=None, steps=None)

Radius of the circle


Divide the shape in the
The part of the circle in equal number of given
degrees as an arc steps.

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Activity 1 - Drawing a Circle


Write a Python program using the turtle module to draw two circles
as shown below.
Code
1 #Turtle program to draw the circles
2 from turtle import *
3 title(“Drawing circles”)
4 circle(50)
5 forward(100)
6 circle(50)

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Demo 2 - Drawing an Arc


Write a Python program using the turtle module to draw a semi circle
with a radius of 50 pixel. Hint: use extent parameter in circle

Code Output
1 from turtle import *
2 pensize(4)
3 circle(100, extent=180)
4 hideturtle()

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Activity 2 - Drawing a Square


Write a Python program using the turtle
Code
module to draw a square with side lengths
of 200 pixels. 1 #drawing the square
2 from turtle import *
3 forward(200)
4 right(90)
5 forward(200)
6 right(90)
Output →
7 forward(200)
8 right(90)
9 forward(200)
10 right(90)
January 2024 © ICT Curriculum, MoESD
PYTHON Key stage IV Class IX

Activity 3 - Drawing an Ice Cream


Write a Python program using the Code
turtle module to draw an ice cream as
shown in the example given below. 1 from turtle import *
2 pensize(4)
3 left(90)
4 circle(100,180)
5 pensize(10)
6 goto(0,0)
Output → 7 right(45)
8 goto(-100,-200)
9 goto(-200,0)
10 done()

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

ACTIVITIES
1. Understanding the use of Pen
3
Controls and Pen Control Methods
2. Activity 1 - Identifying the Methods
PEN CONTROL 3. Demo 1 - Draw a House
4. Activity 2 - Drawing Flag Boundary
5. Activity 3 - Drawing Olympic Ring

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Turtle Pen Control


Turtle Pen Control methods provide control over the drawings on the turtle
canvas. These methods allow you to customize the appearance and behaviour
of the pen used by the turtle to draw on the canvas.

Sl# Methods Purpose


To set the turtle's pen down, so that it will draw a line
1 pendown()
as it moves.
To lift the turtle's pen up, so that it will not draw a line
2 penup()
as it moves.

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Turtle Pen Control (cont.)

SI# Command Purpose


To set the width of the turtle's pen. The width is
3 pensize(width)
specified in pixels.

4 pencolor(color) To set the color of the turtle's pen. *

To control the speed of the turtle. where speed


5 speed(speed)
is an integer or a string. **

goto(x, y) setpos(x,y) Move the turtle to the specified x, y coordinates


6
setposition(x,y) on the screen.

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Activity 1 - Identifying the Methods


Watch the following video or observe the image and list down the
methods used in the program.

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Activity 1 - Solution
The methods used in the program are as the following:

bgcolor(“blanched almond “)

pencolor(“red”)
pencolor(“blue”)
pensize(6)
pensize(3)
forward(100)
circle(100)
left(90)

penup()
moves the turtle
forward(100) →
to a new position
pendown()
January 2024 © ICT Curriculum, MoESD
PYTHON Key stage IV Class IX

Demo 1 - Draw a House


Write a Python program to draw a simple house as shown below.

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Demo 1 - Solution
Code
1 from turtle import * 11 left(90) 21 right(90)
2 pensize(5) 12 forward(150) 22 forward(80)
3 penup() 13 left(90) 23 left(90)
4 goto(-100,0) 14 penup() 24 penup()
5 pendown() 15 goto(-20,0) 25 goto(-130,150)
6 forward(200) 16 pendown() 26 pendown()
7 left(90) 17 left(90) 27 forward(260)
8 forward(150) 18 forward(80) 28 goto(0,200)
9 left(90) 19 right(90) 29 goto(-130,150)
10 forward(200) 20 forward(40) 30 penup()

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Activity 2 - Drawing Flag Boundary


Write a Python program to draw the boundary of the Bhutan Flag
as shown below. You will fill the colour after learning the colour fill
methods.

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Activity 2 - Solution

Code
1 from turtle import * 10 forward(300)
2 pensize(3) 11 right(146)
3 shape("turtle") 12 forward(360)
4 penup() 13 left(180)
5 goto(-200,0) 14 forward(360)
6 pendown() 15 right(124)
7 left(90) 16 forward(200)
8 forward(200) 17 right(90)
9 right(90) 18 forward(300)

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Activity 3 - Drawing Olympic Ring


Write a Python program using turtle module to draw an olympic logo as shown
below.

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Activity 3 - Solution

Code
1 from turtle import * 10 goto(0, -25) 19 penup()
2 pensize(5) 11 pendown() 20 goto(-55, -75)
3 color("blue") 12 circle(45) 21 pendown()
4 penup() 13 color("red") 22 circle(45)
5 goto(-110, -25) 14 penup() 23 color("green")
6 pendown() 15 goto(110, -25) 24 penup()
7 circle(45) 16 pendown() 25 goto(55, -75)
8 color("black") 17 circle(45) 26 pendown()
9 penup() 18 color("yellow") 27 circle(45)

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

ACTIVITIES
1. Understanding Color Control
Methods
4 2. Demo - Colouring a Circle
3. Activity 1 - Coloring a Circle
COLOUR FILL 4. Activity 2 - Colouring Bhutan Flag
5. Activity 3 - Check Your
Understanding
6. Activity 4 - Drawing a YouTube
logo

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Python Colour Fills


In Python turtle module, the colour fill methods are used to control the filling of
shapes drawn by the turtle. When you draw a closed shape, such as a polygon
or a circle, you can use colour fill methods to specify the colour that fills the
interior of the shape.

Sl# Methods Purpose


Tells turtle to fill in any closed shapes that are
1 begin_fill()
drawn
Tells turtle to stop filling in closed shapes that are
2 end_fill()
drawn

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Demo - Colouring a Circle


Write a Python program using the turtle module to draw a circle filled
with purple colour.
Output

Code
1 from turtle import *
2 shape("turtle")
3 begin_fill()
4 color("purple")
5 circle(50)
6 end_fill()

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Activity 1 - Colouring Circles


Write a Python program in your notebook using the turtle module to
create four different circles as shown below. Then check the drawings on your
computer.

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Activity 1 - Solution
1 from turtle import * 16 penup()
2 pensize(5) 17 forward(100)
3 shape("turtle") 18 pendown()
4 penup() 19 color("purple", "orange")
5 goto(-150,0) 20 begin_fill()
6 pendown() 21 circle(40)
7 color("pink") 22 end_fill()
Code

8 begin_fill() 23 penup()
9 circle(40) 24 forward(100)
10 end_fill() 25 pendown()
11 penup() 26 color("purple", "orange")
12 forward(100) 27 pensize(9)
13 pendown() 28 begin_fill()
14 color("blue") 29 circle(40)
15 circle(40) 30 end_fill()
January 2024 © ICT Curriculum, MoESD
PYTHON Key stage IV Class IX

Activity 2 - Colouring Bhutan Flag


Write a Python program using the turtle module to draw the National
flag of Bhutan as shown below. What does each colour signify? What
has to be added to complete the flag?

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Activity 2 - Solution

Code
1 from turtle import * 11 left(90) 21 begin_fill()
2 pensize(3) 12 forward(200) 22 left(180)
3 shape("turtle") 13 right(90) 23 forward(360)
4 penup() 14 forward(300) 24 right(124)
5 goto(-200,0) 15 right(146) 25 forward(200)
6 pendown() 16 forward(360) 26 right(90)
7 fillcolor(“yellow”) 17 end_fill() 27 forward(300)
8 begin_fill() 18 fillcolor(”orange”) 28 end_fill()

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Activity 3 - Check Your Understanding


Write the answers for the following questions in your notebook.:
1. What does the begin_fill() method in Python turtle module signify?
Ans: Marks the beginning of the colour fill

2. In the turtle module, what happens if you call end_fill() without first calling
begin_fill()?
Ans: If you forget to call begin_fill() before using end_fill(), the turtle
assumes that there is no shape to fill, and as a result, the colour filling
process doesn't take place.

3. What is the default colour used for filling shapes if fillcolor() is not explicitly
set? (Choose the correct answer from the option given)
a) Red b) Green c) Black
January 2024 © ICT Curriculum, MoESD
PYTHON Key stage IV Class IX

Activity 4 - Drawing a YouTube Logo

Write a Python program


using the turtle module to
draw a YouTube logo as
shown alongside.

Hint: use the methods such as circle(), color(), begin_fill(), end_fill()


January 2024 © ICT Curriculum, MoESD
PYTHON Key stage IV Class IX

Activity 4 - Solution
1 from turtle import * 13 forward(100)
2 speed(0) 14 circle(20,90)
3 pensize(5) 15 end_fill()
4 color("red") 16 penup()
5 goto(-100,0) 17 goto(20,70)
Code

6 begin_fill() 18 pendown()
7 forward(160) 19 color("white")
8 circle(20,90) 20 begin_fill()
9 forward(100) 21 left(90)
10 circle(20,90) 22 circle(40,360,3)
11 forward(160) 23 end_fill()
12 circle(20,90) 24 hideturtle()
January 2024 © ICT Curriculum, MoESD
PYTHON Key stage IV Class IX

ACTIVITIES
1. Understanding Text Control
Methods
5 2. Demo - Labelling a Circle
3. Activity 1 - Colouring the House
TEXT METHODS 4. Activity 2 - Drawing a Smiley face
5. Activity 3 - Check Your
Understanding
6. Activity 4 - Drawing Sunset

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Text Methods
write() method in Python turtle module is used to write a text on the turtle
canvas.

Example
Method Alignment of the text

write(“Hello World!”,align="center",font=("Arial",16,"normal"))

String to write Font

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Demo - Labelling a Circle


Write a Python program using the turtle module to insert the text
‘Circle’ as shown below.

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Demo - Solution
Code
1 from turtle import *
2 pencolor("red")
3 circle(100)
4 penup()
5 goto(0,100)
6 pendown()
7 color("blue")
8 write("Circle", align="center", font=("Georgia",16,"bold"))

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Activity 1 - Colouring the House


Write a Python program to draw and colour a house as shown in
the image given below.
● Colour the roof green
● Colour the wall pink
● Colour the door brown
● Add a text “A house!” below the house
● Use the font “Georgia” and font size 22 for the text

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Activity 1 - Solution

6 fillcolor("pink")
Code 7 begin_fill()
1 from turtle import * 8 forward(200)
2 pensize(5) 9 left(90)
10 forward(150) Set the
3 penup()
11 left(90) color of the
4 goto(-100,0)
12 forward(200) wall, fill and
5 pendown()
13 left(90) draw the
14 forward(150) wall.
15 left(90)
Import the turtle module, set 16 end_fill()
the pensize, set the position of 17 penup()
the turtle
January 2024 © ICT Curriculum, MoESD
PYTHON Key stage IV Class IX

Activity 1 - Solution (cont.)


18 goto(-20,0)
19 pendown()
20 fillcolor("brown")
21 begin_fill()
Set the position to draw 22 left(90)
the door, select the color 23 forward(80)
to fill the door, then draw 24 right(90)
and fill the door 25 forward(40)
26 right(90)
27 forward(80)
28 end_fill()
29 left(90)
30 penup()

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Activity 1 - Solution (cont.)

31 goto(-130,150)
32 pendown()
33 fillcolor("green")
34 begin_fill() Set the position to draw
35 forward(260) the roof, select the color
36 goto(0,200) to fill the roof, then draw
37 goto(-130,150) and fill the roof.
38 penup() Add text ‘A house’ using
39 end_fill() write() method.
40 penup()
41 goto(0,-40)
42 color("blue")
43 write("A house!",align="center",font=("Georgia",22))

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Activity 2 - Drawing a Smiley Face

Write a Python program using Code


the turtle module to draw a
1 from turtle import *
smiley face as shown below.
2 # Set up the turtle
3 speed(2)
4 # Draw the face
5 penup()
6 fillcolor("yellow")
7 goto(0, -100)
8 pendown()
9 begin_fill()
10 circle(100)
11 end_fill()
January 2024 © ICT Curriculum, MoESD
PYTHON Key stage IV Class IX

Activity 2 - Solution (cont.)


12 # Draw the eyes 26 # Draw the smile
13 penup() 27 penup()
14 fillcolor("black") 28 goto(-50, -40)
15 goto(-30, 20) 29 pendown()
16 pendown() 30 right(60)
17 begin_fill() 31 circle(60, 120)
18 circle(15) 32 # Hide the turtle
19 end_fill() 33 hideturtle()
20 penup()
21 goto(30, 20)
22 pendown()
23 begin_fill() Output →
24 circle(15)
25 end_fill()
January 2024 © ICT Curriculum, MoESD
PYTHON Key stage IV Class IX

Activity 3 - Check your understanding


Write the answers for the following questions in your notebook.
1. How would you lift the pen in the turtle module to allow the turtle to move
without drawing?
a) raisepen() b) penup()
c) pen_up() d) lift_pen()

2. How can you set the turtle's speed to the maximum in the turtle module?
a) set_speed("fastest") b) speed("fastest")
c) max_speed() d) turbo_mode()

3. The size (width, height) method sets the title of the turtle graphics window.
(True/False)

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Activity 3 - Check your understanding(Cont.)

4. Which method sets the pen color in the Turtle module?


a) set_pen_color("color") b) pensize(width)
c) pencolor("color") d) set_color("color")

5. The method that sets the background color of the turtle graphics window
is bgcolor("_____").
color (Fill in the blanks)

6. The forward(distance) method can be used to go backward by using a


distance. (True/False)

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Activity 4 - Drawing Sunset

Observe the given art carefully


and recreate it in Python
program using the turtle module.

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Activity 4 Solution
Code
1 from turtle import* 15 right(90)
2 title("Sunset") 16 forward(200)
3 shape("turtle") 17 right(90)
4 bgcolor("cyan") 18 forward(400)
5 begin_fill() 19 right(90)
6 color("yellow") 20 forward(200)
7 left(90) 21 right(90)
8 circle(75, 180) 22 forward(200)
9 end_fill() 23 end_fill()
10 home() 24 home()
11 begin_fill() 25 penup()
12 color("blue") 26 goto(0,130)
13 forward(200) 27 pendown()
14 forward(200) 28 write("Sunset",font=("Impact",30))
January 2024 © ICT Curriculum, MoESD
PYTHON Key stage IV Class IX

Key
Points
● Turtle is a built-in module for drawing graphics in Python.
● There are two ways to import turtle: import turtle and from turtle import *
● We can customize turtle window using setup(x, y), title(" "), shape("turtle"),
bgcolor("color"), showturtle(), hideturtle() methods.
● We can manage drawing on turtle with forward(), backward(), left(), and
right(), penup(), pendown(), and customize pen attributes.
● The write( ) method is used to insert text on the turtle canvas.
● The immediate visual feedback in turtle can make programming more
engaging and intuitive, especially for younger learners or those new to coding.

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

བཀྲིན་ཆེ།
THANK YOU

January 2024 © ICT Curriculum, MoESD

You might also like