Menu

[Solved] Exercise 41 Modify Polygons Program Chapter 7 Book Examples See Pages 209 212 213 217 Fold Q37177336

Exercise 4.1 Modify the polygons program in the chapter 7 BookExamples (see pages 209, 212, 213 and 217) folder to create atriangle. Replace the square function calls in the random patternsprogram with the triangles function calls. You will need to enterthe code from the pages above and modify the square function toimplement a triangle. Final software should include these functionsin files: polygons.py triangle hexagon radialHexagons radialPatternrandomPatterns.py drawPattern main Most of the code can be enteredfrom the book. Don’t forget the turtle.cfg file which is describedin the book and lecture video.

def drawSquare(t, x, y, Tength): Draws a square with the given turtle t, an upper-left corner point (x, y), and a sides lendef hexagon(t, Tength): Draws a hexagon with the given 1ength. for count in range(6): t. forward(length t.left (60)def radial Hexagons (t, n, length): Draws a radial pattern of n hexagons with the given length. for count in range (n):def radialpattern(t, n, Tength, shape) Draws a radial pattern of n shapes with the given length. for count in range(n): s>>from turtle import Turtle >>> t = Turtle() >t.positionO C0.0, 0.0) >>>t.heading 0.0 >>t.isdown( Truefrom turtle import Turtle import random def randomWalk (t, turns, distance20): iTurns a random number of degrees and moves a

def drawSquare(t, x, y, Tength): “Draws a square with the given turtle t, an upper-left corner point (x, y), and a side’s length.””” t.upO t.goto(x, y) t.setheading(270) t.down O for count in range(4): t. forward(length t.left(90) def hexagon(t, Tength): “””Draws a hexagon with the given 1ength.” for count in range(6): t. forward(length t.left (60) def radial Hexagons (t, n, length): “””Draws a radial pattern of n hexagons with the given length.””” for count in range (n): hexagon (t, length) t. left(360 n) def radialpattern(t, n, Tength, shape) “Draws a radial pattern of n shapes with the given length.””” for count in range(n): shape (t, length) t.left (360 n) >>> t = Turtle() >radialPattern(t, n10, length50, shape square) >>>t.clearO) >>> radial Pattern (t, n = 10, length = 50, shape = hexagon) >>from turtle import Turtle >>> t = Turtle() >t.positionO C0.0, 0.0) >>>t.heading 0.0 >>t.isdown( True from turtle import Turtle import random def randomWalk (t, turns, distance20): “iTurns a random number of degrees and moves a given distance for a fixed number of turns.””” for x in range(turns): t.left(random.randint(0, 270)) else: t.right(random.randint (0, 270)) t.forward (distance) def mainO: tTurtleO t.shape(“turtle” randomWalk(t, 40, 30) if name”main”: main Show transcribed image text def drawSquare(t, x, y, Tength): “Draws a square with the given turtle t, an upper-left corner point (x, y), and a side’s length.””” t.upO t.goto(x, y) t.setheading(270) t.down O for count in range(4): t. forward(length t.left(90)
def hexagon(t, Tength): “””Draws a hexagon with the given 1ength.” for count in range(6): t. forward(length t.left (60)
def radial Hexagons (t, n, length): “””Draws a radial pattern of n hexagons with the given length.””” for count in range (n): hexagon (t, length) t. left(360 n)
def radialpattern(t, n, Tength, shape) “Draws a radial pattern of n shapes with the given length.””” for count in range(n): shape (t, length) t.left (360 n) >>> t = Turtle() >radialPattern(t, n10, length50, shape square) >>>t.clearO) >>> radial Pattern (t, n = 10, length = 50, shape = hexagon)
>>from turtle import Turtle >>> t = Turtle() >t.positionO C0.0, 0.0) >>>t.heading 0.0 >>t.isdown( True
from turtle import Turtle import random def randomWalk (t, turns, distance20): “iTurns a random number of degrees and moves a given distance for a fixed number of turns.””” for x in range(turns): t.left(random.randint(0, 270)) else: t.right(random.randint (0, 270)) t.forward (distance) def mainO: tTurtleO t.shape(“turtle” randomWalk(t, 40, 30) if name”main”: main

Expert Answer


Answer to Exercise 4.1 Modify the polygons program in the chapter 7 Book Examples (see pages 209, 212, 213 and 217) folder to crea… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *