Search Header Logo
[IGCS] For-loop with tutle

[IGCS] For-loop with tutle

Assessment

Presentation

Social Studies, Computers

9th Grade

Practice Problem

Hard

Created by

Andy tsui

Used 6+ times

FREE Resource

11 Slides • 2 Questions

1

[IGCS] For-loop with tutle

Slide image

2

Introducing Turtle graphics

  • In REPL.it, start a new "Python with Turtle" project

  • Name it with "for-loop-with-turtle"

  • On the first two line, do:

3

Enter the following in your new REPL

import turtle

t = turtle.Turtle()

4

Run, and on the command console, try:

  • t.forward(50)

  • t.left(50)

  • Note what are they doing? and can you guess how to go backward and rotate right?

5

Drawing regular shapes

  • Try to draw a square

6

Fill in the Blank

For drawing a square, How many time we need to repeat:

t.forward(50)

t.right(50)

7

Now try to draw the square with For-loop

8

Multiple Choice

Now we try to draw equilateral triangle, we need to repeat 3 times the following:

t.forward(50)

t.right([X])

What is X?

1

60

2

120

3

30

4

150

9

120 is the exterior angle

Can you recall the formula for it?

Slide image

10

Exterior angle of n-side polygon

ext_angle = 360 / n

11

Practice time, using for loops to:

  • Draw a Pentagon of each side 20 unit long

  • Draw a Hexagon of 20 unit long

  • Draw an Octagon of 20 unit long

  • Draw a Decagon of 20 unit long

12

Finding the pattern

In a regular polygon:


for i in range (n):

⠀t.forward(20)

⠀t.right(?)

13

Summary

For loop is for counting and the counter can be used as a variable

It is usually not advisable to change the counter value inside the loop

[IGCS] For-loop with tutle

Slide image

Show answer

Auto Play

Slide 1 / 13

SLIDE