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

while rings >0: b. Write a function shoot that simulates firing an arrow towards

ID: 3670837 • Letter: W

Question

while rings >0: b. Write a function shoot that simulates firing an arrow towards the target. The effect of shoot should be to indicate visually where on the target (or near the target) the "arrow" lands. You can use turtle.dot() for this. The landing position should be at a pseudo- random position on or near the target. Look at the documentation for the Python module random and choose a suitable function to help you generate a pseudo-random position. To use turtle.dot(), you will need a random number for both the x-coordinate and the y-coordinate, so generate two random numbers for one dot. The return value of target he elecar the trton should be dtocum # Draw the rings here. rings + 1 tuntle dotD def shoot : m " "Simulate an arrow shot Return: the distance of the shot from the origin."" " # Code for simulating an arrow shot goes here. # Calculate the distance of the shot from the origin. return distance shoot should be the distance between theCa origin and the point at which the arrow lands. You can use turtle.distance() for this.

Explanation / Answer

Set turtle shape to shape with given name or, if name is not given, return name of current shape. Shape with name must exist in the TurtleScreen’s shape dictionary. Initially there are the following polygon shapes: “arrow”, “turtle”, “circle”, “square”, “triangle”, “classic”


>>> turtle.shape()
'classic'
>>> turtle.shape("turtle")
>>> turtle.shape()
'turtle'

turtle.setx(x)

Parameters:   x – a number (integer or float)
Set the turtle’s first coordinate to x, leave second coordinate unchanged.

>>> turtle.position()
(0.00,240.00)
>>> turtle.setx(10)
>>> turtle.position()
(10.00,240.00)


turtle.sety(y)
Parameters:   y – a number (integer or float)
Set the turtle’s second coordinate to y, leave first coordinate unchanged.

>>> turtle.position()
(0.00,40.00)
>>> turtle.sety(-10)
>>> turtle.position()
(0.00,-10.00)

turtle.home()
Move turtle to the origin – coordinates (0,0) – and set its heading to its start-orientation (which depends on the mode, see mode()).

>>> turtle.heading()
90.0
>>> turtle.position()
(0.00,-10.00)
>>> turtle.home()
>>> turtle.position()
(0.00,0.00)
>>> turtle.heading()
0.0

turtle.circle(radius, extent=None, steps=None)
Parameters:  
radius – a number
extent – a number (or None)
steps – an integer (or None)
Draw a circle with given radius. The center is radius units left of the turtle; extent – an angle – determines which part of the circle is drawn. If extent is not given, draw the entire circle. If extent is not a full circle, one endpoint of the arc is the current pen position. Draw the arc in counterclockwise direction if radius is positive, otherwise in clockwise direction. Finally the direction of the turtle is changed by the amount of extent.


>>> turtle.home()
>>> turtle.position()
(0.00,0.00)
>>> turtle.heading()
0.0
>>> turtle.circle(50)
>>> turtle.position()
(-0.00,0.00)
>>> turtle.heading()
0.0
>>> turtle.circle(120, 180) # draw a semicircle
>>> turtle.position()
(0.00,240.00)
>>> turtle.heading()
180.0
turtle.dot(size=None, *color)
Parameters:  
size – an integer >= 1 (if given)
color – a colorstring or a numeric color tuple
Draw a circular dot with diameter size, using color. If size is not given, the maximum of pensize+4 and 2*pensize is used.

>>> turtle.home()
>>> turtle.dot()
>>> turtle.fd(50); turtle.dot(20, "blue"); turtle.fd(50)
>>> turtle.position()
(100.00,-0.00)
>>> turtle.heading()
0.0

turtle.distance(x, y=None)
Parameters:  
x – a number or a pair/vector of numbers or a turtle instance
y – a number if x is a number, else None
Return the distance from the turtle to (x,y), the given vector, or the given other turtle, in turtle step units.

>>> turtle.home()
>>> turtle.distance(30,40)
50.0
>>> turtle.distance((30,40))
50.0
>>> joe = Turtle()
>>> joe.forward(77)
>>> turtle.distance(joe)
77.0