0 оценок0% нашли этот документ полезным (0 голосов)
7 просмотров3 страницы
This document summarizes Valentina Reyes Martínez's problems set for week 4 on graphics and functions using Turtle Geometry. [1] It includes problems to draw basic shapes like squares and triangles using for loops and functions. [2] Problem functions are created to draw the shapes in varying sizes. [3] Higher problems have the student write functions to draw regular polygons of adjustable length and a growing spiral of polygons.
This document summarizes Valentina Reyes Martínez's problems set for week 4 on graphics and functions using Turtle Geometry. [1] It includes problems to draw basic shapes like squares and triangles using for loops and functions. [2] Problem functions are created to draw the shapes in varying sizes. [3] Higher problems have the student write functions to draw regular polygons of adjustable length and a growing spiral of polygons.
This document summarizes Valentina Reyes Martínez's problems set for week 4 on graphics and functions using Turtle Geometry. [1] It includes problems to draw basic shapes like squares and triangles using for loops and functions. [2] Problem functions are created to draw the shapes in varying sizes. [3] Higher problems have the student write functions to draw regular polygons of adjustable length and a growing spiral of polygons.
>>>from turtle import * >>>for x in [100,100,100,100]: forward(x) left(90) >>>done()
Problem 2, make function square ()
Convert the algorithm of Problem #1 to a function that draws a square of any size. By naming this procedure the turtle will remember the command, and the next time we need to draw a similar square we just call its name.
# Problem 2 – Draw a square of any size
>>>from turtle import * >>>def square(): for x in [100,100,100,100]: forward(x) left(90) >>>square() >>>done()
Problem 3, draw multiple squares
With the function of Problem #2 draw several squares of various sizes that share the same left lower vertex.
>>>from turtle import *
>>>def square(lenght): i=0 while i < 360: forward(lenght) left(90) >>>square(7, 100) >>> size = 50 >>> square(size) >>> done()
Problem 4, draw a triangle
Draw an equilateral triangle with the turtle.
There are two options for drawing the tringle:
Calculate the angle of rotation (left) and calculate the units.
The other option is to move the turtle home (), where it started.
Convert the algorithm of Problem #4 to a function that draws a triangle of any size.
>>>from turtle import *
>>>def triangle(): for x in [100,100,100]: forward(x) left(60) >>>triangle() >>>done()
Problem 6, draw a regular polygon
Write a function that draws any regular polygon with the side of adjustable length. A regular polygon is a closed geometric figure in which all of its sides and angles are equal. To draw any regular polygon we need to define the number of sides and, optionally, the length of a side if we want the function to draw polygons of varying size.
>>>from turtle import *
>>>n_sides = int(input("How many sides? ")) >>>angle = 360 / n_sides >>>i = 0 while i < 360: forward(100) left(angle) i += angle >>>done()
Problem 7, draw a growing polygon – Spyral
Write a function that draws a growing regular polygon of various number of sides. It should be able to reproduce any of the drawings below.
I´m sorry teacher, I didn´t understood this very well.