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

Python Suppose there are two non-empty list variables of equal length in Python

ID: 3838572 • Letter: P

Question

Python

Suppose there are two non-empty list variables of equal length in Python called coords and sides.

The variable coords contains sub-lists of size 2, with each of these values representing an x and a y co-ordinate.

The variable sides also contains sub-lists of size 2, with each of these values representing firstly the length then the width of a rectangle.

Also assume there is also a function in Python called draw_rectangle which takes as its parameters two integers representing firstly the length then the width of a rectangle. The function then draws that rectangle using Turtle graphics functions.

Complete the following code to draw each of the rectangles represented by the length-width pairs in the list sides at the x-y co-ordinates contained at the same index in the list coords.

for _______A______

penup______B_______

pendown() ______C_______

goto(coords index) draw rectangle(sideslindex][0], sides index][1]) pair in sides for xy in coords: goto(coords[pair]) goto(xy) draw rectangle() draw rectangle(sides[0][index], sides[1][index]) draw rectangle (sides[0][0], sides[0111]) draw rectangle(sides[0], sides[11) index in range(len sides draw rectangle(sideslindex] index 11, sides index][index 1)

Explanation / Answer

Here is the solution as per the given criteria, please go through it throughly:-

Turtle” is a python feature like a drawing board, which lets you command a

turtle to draw all over it!
#####################################

import turtle
x = float(input("Enter the center x cordinates of the rectangle: "))
y = float(input("Enter the center y cordinates of the rectangle: "))
b = float(input("Enter the value of Breadth: "))
l = float(input("Enter the value of Length: "))
s = turtle.Screen()
turtle.shape("turtle")
turtle.colormode(255)
##to set an RGB value
turtle.color(215, 100, 170) ##to set a pink colour.
turtle.penup()
# start at the center
turtle.goto(x,y)
# head east
turtle.setheading(0)
# go to the middle of the right side
turtle.forward(b / 2)
# turn south, go to south east corner
turtle.setheading(270)
turtle.forward(l / 2)

#put the pen down, start drawing
turtle.pendown()
for heading, distance in zip((180, 90, 0, 270), (b, l, b, l)):
turtle.setheading(heading)
turtle.forward(distance)
turtle.penup()
turtle.exitonclick()

###########################################
Note :
>> If you misdrew anything, then use to erase its drawing board with the "turtle.reset()" directive, or undo the most recent step with "turtle.undo()"

>> If you want that turtle window do not vanishes after the turtle finished its movement then just put "turtle.exitonclick()" at the bottom of your file. This will help the window stays open until you click on it:
################################################

Please run these commands into your window and check out the output