0% found this document useful (0 votes)
96 views7 pages

Turtles Drawing

1. The document discusses using turtle commands in Python to draw pictures and diagrams. It introduces basic commands like forward(), left(), penup(), and pendown(). 2. Debugging is discussed as an important part of the process. Common errors are explored along with how to read error messages to identify issues. 3. Exercises are provided to both generate turtle drawings from given code and write code to produce desired drawings, making use of various commands. This includes changing colors, positioning the turtle precisely, and drawing names and characters.

Uploaded by

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

Turtles Drawing

1. The document discusses using turtle commands in Python to draw pictures and diagrams. It introduces basic commands like forward(), left(), penup(), and pendown(). 2. Debugging is discussed as an important part of the process. Common errors are explored along with how to read error messages to identify issues. 3. Exercises are provided to both generate turtle drawings from given code and write code to produce desired drawings, making use of various commands. This includes changing colors, positioning the turtle precisely, and drawing names and characters.

Uploaded by

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

Turtles Drawing

1. Programming the Turtle


a. Launch the Wing IDE (Click “START” button > type “wing ide” > Press “ENTER”)

if it is not already launched. Start a NEW file (Click icon .). The file will
contain python commands. It will be referred to as the “python program file”.

b. Type the following commands below and click on the green arrow at the
top to execute the code. Record down what you see. Save your python
program file to a folder (Click icon ).

c. Instead of 2 commands, consider that there are now four commands that you
can use: forward(x), left(x), penup(), pendown().

Command Action
forward(x) Instruct the turtle to move x steps in the direction it is facing
left(x) Instruct the turtle to make a x degrees left turn (instead of
just 90 degree)
penup() Instruct the turtle to lift up the pen (i.e. stop drawing)
pendown() Instruct the turtle to put down the pen (i.e. start drawing)

1
d. Take note of the following when writing your turtle commands:
i. The first 2 lines of commands issued must be as follows. You do not
have to worry about what these 2 lines mean at the moment.

ii. Followed by your turtle commands to draw the desired picture.


iii. The last line of command issued must be as follows. Similarly, you do
not have to worry about what this line means at the moment

e. Write the sequence of commands to instruct the turtle to draw the picture as
shown in figure 3 below. Try to do it with the least number of commands.
(Note: We often refer to a collection of commands as “program code” or just
“code”.)

Figure 3 Step

2
2. Debugging your program

a. A software bug (or “bug” in short) is an error, flaw, failure, or fault in a computer
program or system that produces an incorrect or unexpected result, or causes it to
behave in unintended ways. The process of removing the bug from your program is
called “debugging”.

b. When you write code you might encounter some errors due to a bug. For example
you might have mistyped the forward() command as follows:

c. In such a case, when you execute the code, the program stops executing when it
encounters a bug like this and you will see an error similar to the following
appearing in the “python shell” window of the IDE. It is important not to panic and
read the error message carefully.

d. The 2 most important information that you must pay attention to is the line
number and the last line that inform the programmer (you) about the type of
error. In this case, the error happens at line 9 of the program file and the type of
error is a “NameError”. It informs you that the computer does not understand
forwad.

You will encounter many other types of errors at this module. The important thing
to remember is not to worry. There are reasons why errors occur and they can
be corrected.

What are other kinds of errors that you have encountered? Talk to your facilitator
about it.

3
3. What is the turtle drawing?

a. In the previous exercise, you gave the turtle a sequence of commands to draw 2
pictures. In this exercise, you will step into the shoes of the turtle and try to
predict what drawing will be produced by studying the sequence of commands.
Read the code given in figure below and produce the corresponding drawings based
on the commands given.

4
4. More Turtle Commands

4.1. Changing the Drawing Colour

a. You can change the color of the line drawn by the turtle using the pencolor(x)
command. Type out the commands below in a new program file, execute it and
note down what you observed. (NOTE: the value of x can be ‘red’, ‘blue’, ‘yellow’,
‘purple’ etc. The word must be enclosed in quotes.)

Experiment with different values of x in the pencolor(x) command.

b. Modify the code such that the turtle is able to draw a ‘blue’ square of length 200
steps with the turtle starting and ending at the same location facing the
right.

5
4.2 Moving to a Desired Location Faster!

a. Type out the code below in a new python file and execute it. Experiment with
different values for the goto(x,y) command and answer the questions that
follow.

i. By studying the drawing generated by the code above, what additional


effect does the goto(x,y) command create?

ii. How many values does the goto(x, y) command take in? What do the
values represent?

b. Write the code to draw the figure below. Make use of the goto(x,y) command to
position the turtle.

6
50

50

40

40
40

80

5. Draw your Name


After teaching the turtle how to draw, you are now ready to teach the turtle how to
draw your name. You can have different colors for different letters.

Note: You can make the turtle make a left turn of 300 by issuing the following
command: left(30)

Proceed to write the code to produce you name.

6. Draw your favourite cartoon character.

Choose a cartoon character, draw it on paper and convert it to turtle codes.

You might also like