Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using python define a function that uses a turtle object to fill in a rectangle

ID: 3889567 • Letter: U

Question

Using python define a function that uses a turtle object to fill in a rectangle with diagonal lines from the bottom left corner to the top right corner. The lines need to be equally spaced. The function needs to define these parameters: the turtle object, the color of the lines, the x and y coordinates of the bottom left corner, the width and height of the rectangle, and the space between the lines. Before the function returns the turtle needs to be at the position and heading it was in before the function was called. Do not use conditional statements.

Explanation / Answer

from turtle import *
def rect():
    canvas = Screen()
    canvas.setup(300,300)

    r = Turtle()
    r.write('Rectangle')
    r.color('blue')
    r.forward(100)          # make sarah draw a square
    r.color('red')
    r.left(90)
    r.forward(100)
    r.left(90)
    r.color('yellow')
    r.forward(100)
    r.left(90)
    r.color('green')
    r.forward(100)
    r.left(90)
    r.write('Rectangle')
    canvas.exitonclick()
rect()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote