1 of 62

དཔལ་ལྡན་འབྲུག་གཞུང་། ཤེས་རིག་དང་རིག་རྩལ་གོང་འཕེལ་ལྷན་ཁག།

Department of School Education

Ministry of Education & Skills Development

Python Coding

January 2024

Class IX ICT Curriculum

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

2 of 62

TURTLE MODULE

Key Concept # 4

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

3 of 62

Concept Overview

Coding Concept

Sub-Concepts

Python Turtle Module

  • Importing the turtle module
  • Turtle window setting - size(), title(), shape(), bgcolor(), showturtle(), hideturtle()
  • Turtle basic motions methods- forward(), backward(), left(), right(), circle()
  • Turtle pen control methods - pencolor(), pensize(), pendown(), penup(), speed(), goto(), setpos(), setposition()
  • Colour control - begin_fill(), end_fill()
  • Text method - write()

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

4 of 62

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

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

5 of 62

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

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

6 of 62

Importance of Turtle Module

Easy Start

Helps beginners understand coding basics like loops 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

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

7 of 62

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:

Using the import turtle statement - this imports the entire turtle module and allows you to use all of its functions and classes.

1

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

2

Direct import

Import Everything

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

8 of 62

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 * .

import turtle

Tk=turtle.Turtle()

for x in range(4)

Tk.forward(200)

Tk.right(90)

Tk.done()

1

from turtle import *

for x in range(4)

forward(200)

right(90)

done()

2

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

9 of 62

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

Colour control

Text method

Window setting

Pen control

Basic motions

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

10 of 62

WINDOW SETTING

ACTIVITIES

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

1

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

11 of 62

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

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

12 of 62

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

3

shape("turtle")

To change the turtle graphics object to one of the 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

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

13 of 62

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

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

14 of 62

Demo - Solution

1

2

3

4

5

6

7

8

#import the turtle module

from turtle import *

# Set the background color of the window to yellow

bgcolor("yellow")

#Set the window size to 300x250 pixels

setup(350,250)

# Set the title of the Turtle window

title("Colorful Turtle Canvas")

Code

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

15 of 62

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

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

16 of 62

Activity 1 - Solution

1

2

3

4

5

6

7

8

9

10

#import the turtle module

from turtle import *

# Create a Turtle object with the shape "square"

shape("square")

#Change the window size height=400 and width=350

setup(height=400,width=350)

# Set the title of the Turtle window

title("This is a title to the window!")

# Set the background color of the window to pink

bgcolor("pink")

Code

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

17 of 62

BASIC MOTIONS

ACTIVITIES

  1. Understanding Turtle Motions and Motion Methods
  2. Demo 1 - Drawing a Line
  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

2

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

18 of 62

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

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

19 of 62

Example 1 - Turning Left/Right

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

1

2

3

4

5

6

7

#turtle program to turn the turtle left and then right

from turtle import *

title(“Turning left and right”)

left(90)

forward(100)

right(90)

forward(100

Code

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

20 of 62

Demo 1 - Drawing a line

Write a Python program using the turtle module to move 100

pixels forward and then move 100 pixels backward.

1

2

3

4

5

#turtle program to draw the moving forward and backward

from turtle import *

title("Moving forward and backward")

forward(100)

backward(100)

Code

Output

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

21 of 62

Drawing a Circle

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

The part of the circle in degrees as an arc

Syntax →

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

Radius of the circle

Divide the shape in the equal number of given steps.

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

22 of 62

Activity 1 - Drawing a Circle

Code

Write a Python program using the turtle module to draw two circles as shown below.

1

2

3

4

5

6

#Turtle program to draw the circles

from turtle import *

title(“Drawing circles”)

circle(50)

forward(100)

circle(50)

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

23 of 62

Demo 2 - Drawing an Arc

Code

Output

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

1

2

3

4

from turtle import *

pensize(4)

circle(100, extent=180)

hideturtle()

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

24 of 62

Code

Activity 2 - Drawing a Square

Output

Write a Python program using the turtle module to draw a square with side lengths of 200 pixels.

1

2

3

4

5

6

7

8

9

10

#drawing the square

from turtle import *

forward(200)

right(90)

forward(200)

right(90)

forward(200)

right(90)

forward(200)

right(90)

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

25 of 62

Code

Activity 3 - Drawing an Ice Cream

Output

Write a Python program using the turtle module to draw an ice cream as shown in the example given below.

1

2

3

4

5

6

7

8

9

10

from turtle import *

pensize(4)

left(90)

circle(100,180)

pensize(10)

goto(0,0)

right(45)

goto(-100,-200)

goto(-200,0)

done()

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

26 of 62

PEN CONTROL

ACTIVITIES

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

3

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

27 of 62

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

1

pendown()

To set the turtle's pen down, so that it will draw a line as it moves.

2

penup()

To lift the turtle's pen up, so that it will not draw a line as it moves.

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

28 of 62

Turtle Pen Control (cont.)

SI#

Command

Purpose

3

pensize(width)

To set the width of the turtle's pen. The width is specified in pixels.

4

pencolor(color)

To set the color of the turtle's pen. *

5

speed(speed)

To control the speed of the turtle. where speed is an integer or a string. **

6

goto(x, y) setpos(x,y) setposition(x,y)

Move the turtle to the specified x, y coordinates on the screen.

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

29 of 62

Activity 1 - Identifying the Methods

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

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

30 of 62

Activity 1 - Solution

bgcolor(“blanched almond “)

pencolor(“blue”)

pencolor(“red”)

pensize(3)

circle(100)

moves the turtle to a new position

penup()

pendown()

forward(100)

pensize(6)

forward(100)

left(90)

The methods used in the program are as the following:

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

31 of 62

Demo 1 - Draw a House

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

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

32 of 62

Demo 1 - Solution

Code

1

2

3

4

5

6

7

8

9

10

from turtle import *

pensize(5)

penup()

goto(-100,0)

pendown()

forward(200)

left(90)

forward(150)

left(90)

forward(200)

11

12

13

14

15

16

17

18

19

20

left(90)

forward(150)

left(90)

penup()

goto(-20,0)

pendown()

left(90)

forward(80)

right(90)

forward(40)

21

22

23

24

25

26

27

28

29

30

right(90)

forward(80)

left(90)

penup()

goto(-130,150)

pendown()

forward(260)

goto(0,200)

goto(-130,150)

penup()

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

33 of 62

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

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

34 of 62

Activity 2 - Solution

Code

1

2

3

4

5

6

7

8

9

from turtle import *

pensize(3)

shape("turtle")

penup()

goto(-200,0)

pendown()

left(90)

forward(200)

right(90)

10

11

12

13

14

15

16

17

18

forward(300)

right(146)

forward(360)

left(180)

forward(360)

right(124)

forward(200)

right(90)

forward(300)

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

35 of 62

Activity 3 - Drawing Olympic Ring

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

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

36 of 62

Activity 3 - Solution

Code

1

2

3

4

5

6

7

8

9

from turtle import *

pensize(5)

color("blue")

penup()

goto(-110, -25)

pendown()

circle(45)

color("black")

penup()

10

11

12

13

14

15

16

17

18

goto(0, -25)

pendown()

circle(45)

color("red")

penup()

goto(110, -25)

pendown()

circle(45)

color("yellow")

192021222324

25

2627

penup()

goto(-55, -75)

pendown()

circle(45)

color("green")

penup()

goto(55, -75)

pendown()

circle(45)

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

37 of 62

COLOUR FILL

ACTIVITIES

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

4

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

38 of 62

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

1

begin_fill()

Tells turtle to fill in any closed shapes that are drawn

2

end_fill()

Tells turtle to stop filling in closed shapes that are drawn

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

39 of 62

Demo - Colouring a Circle

Code

Output

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

1

2

3

4

5

6

from turtle import *

shape("turtle")

begin_fill()

color("purple")

circle(50)

end_fill()

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

40 of 62

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

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

41 of 62

Activity 1 - Solution

Code

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

from turtle import *

pensize(5)

shape("turtle")

penup()

goto(-150,0)

pendown()

color("pink")

begin_fill()

circle(40)

end_fill()

penup()

forward(100)

pendown()

color("blue")

circle(40)

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

penup()

forward(100)

pendown()

color("purple", "orange")

begin_fill()

circle(40)

end_fill()

penup()

forward(100)

pendown()

color("purple", "orange")

pensize(9)

begin_fill()

circle(40)

end_fill()

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

42 of 62

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

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

43 of 62

Activity 2 - Solution

Code

1

2

3

4

5

6

7

8

from turtle import *

pensize(3)

shape("turtle")

penup()

goto(-200,0)

pendown()

fillcolor(“yellow”)

begin_fill()

11

12

13

14

15

16

17

18

left(90)

forward(200)

right(90)

forward(300)

right(146)

forward(360)

end_fill()

fillcolor(”orange”)

21

22

23

24

25

26

27

28

begin_fill()

left(180)

forward(360)

right(124)

forward(200)

right(90)

forward(300)

end_fill()

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

44 of 62

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

  1. 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.

  1. 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

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

45 of 62

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

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

46 of 62

Activity 4 - Solution

Code

1

2

3

4

5

6

7

8

9

10

11

12

from turtle import *

speed(0)

pensize(5)

color("red")

goto(-100,0)

begin_fill()

forward(160)

circle(20,90)

forward(100)

circle(20,90)

forward(160)

circle(20,90)

13

14

15

16

17

18

19

20

21

22

23

24

forward(100)

circle(20,90)

end_fill()

penup()

goto(20,70)

pendown()

color("white")

begin_fill()

left(90)

circle(40,360,3)

end_fill()

hideturtle()

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

47 of 62

TEXT METHODS

ACTIVITIES

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

5

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

48 of 62

Text Methods

Example

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

Method

Alignment of the text

String to write

Font

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

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

49 of 62

Demo - Labelling a Circle

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

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

50 of 62

Demo - Solution

Code

1

2

3

4

5

6

7

8

from turtle import *

pencolor("red")

circle(100)

penup()

goto(0,100)

pendown()

color("blue")

write("Circle", align="center", font=("Georgia",16,"bold"))

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

51 of 62

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

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

52 of 62

Activity 1 - Solution

Code

1

2

3

4

5

from turtle import *

pensize(5)

penup()

goto(-100,0)

pendown()

6

7

8

9

10

11

12

13

14

15

16

17

fillcolor("pink")

begin_fill()

forward(200)

left(90)

forward(150)

left(90)

forward(200)

left(90)

forward(150)

left(90)

end_fill()

penup()

Set the color of the wall, fill and draw the wall.

Import the turtle module, set the pensize, set the position of the turtle

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

53 of 62

Activity 1 - Solution (cont.)

Set the position to draw the door, select the color to fill the door, then draw and fill the door

18

19

20

21

22

23

24

25

26

27

28

29

30

goto(-20,0)

pendown()

fillcolor("brown")

begin_fill()

left(90)

forward(80)

right(90)

forward(40)

right(90)

forward(80)

end_fill()

left(90)

penup()

Set the position to draw the door, select the color to fill the door, then draw and fill the door

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

54 of 62

Activity 1 - Solution (cont.)

Set the position to draw the roof, select the color to fill the roof, then draw and fill the roof.

Add text ‘A house’ using write() method.

31

32

33

34

35

36

37

38

39

40

41

42

43

goto(-130,150)

pendown()

fillcolor("green")

begin_fill()

forward(260)

goto(0,200)

goto(-130,150)

penup()

end_fill()

penup()

goto(0,-40)

color("blue")

write("A house!",align="center",font=("Georgia",22))

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

55 of 62

Activity 2 - Drawing a Smiley Face

Write a Python program using the turtle module to draw a smiley face as shown below.

1

2

3

4

5

6

7

8

9

10

11

from turtle import *

# Set up the turtle

speed(2)

# Draw the face

penup()

fillcolor("yellow")

goto(0, -100)

pendown()

begin_fill()

circle(100)

end_fill()

Code

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

56 of 62

Activity 2 - Solution (cont.)

Output →

12

13

14

15

16

17

18

19

20

21

22

23

24

25

# Draw the eyes

penup()

fillcolor("black")

goto(-30, 20)

pendown()

begin_fill()

circle(15)

end_fill()

penup()

goto(30, 20)

pendown()

begin_fill()

circle(15)

end_fill()

26

27

28

29

30

31

32

33

# Draw the smile

penup()

goto(-50, -40)

pendown()

right(60)

circle(60, 120)

# Hide the turtle

hideturtle()

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

57 of 62

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()

  1. 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()

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

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

58 of 62

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("_____"). (Fill in the blanks)

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

color

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

59 of 62

Activity 4 - Drawing Sunset

Observe the given art carefully and recreate it in Python program using the turtle module.

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

60 of 62

Activity 4 Solution

1

2

3

4

5

6

7

8

9

10

11

12

13

14

from turtle import*

title("Sunset")

shape("turtle")

bgcolor("cyan")

begin_fill()

color("yellow")

left(90)

circle(75, 180)

end_fill()

home()

begin_fill()

color("blue")

forward(200)

forward(200)

15

16

17

18

19

20

21

22

23

24

25

26

27

28

right(90)

forward(200)

right(90)

forward(400)

right(90)

forward(200)

right(90)

forward(200)

end_fill()

home()

penup()

goto(0,130)

pendown()

write("Sunset",font=("Impact",30))

Code

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

61 of 62

  • 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.

Key Points

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

62 of 62

བཀྲིན་ཆེ།

THANK YOU

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD