Question: Throwing Darts Now that we have our dartboard setup, we can throw darts. We will assume that we are good enough at throwing darts that

 Throwing Darts Now that we have our dartboard setup, we can

throw darts. We will assume that we are good enough at throwing

Throwing Darts Now that we have our dartboard setup, we can throw darts. We will assume that we are good enough at throwing darts that we always hit the wood. However, sometimes the darts will hit the dartboard and sometimes they will miss In order to simulate throwing the darts, we can generate two random numbers between zero and one. The first will be the x coordinate" of the dart and the second will be the "y coordinate" However, we have a problem. The coordinates for the dartboard go from -1 to 1 How can we turn a random number between 0 to 1 into a random number between -1 and 1? We know that random.randomO will retum a number between 0 and 1. We may obtain a number between-1 and 1by calculating random.random0 *2 -1 Activity 4: The program has been started for you. You need to fill in the part that will throw the dart" Once you know the x,y coordinate, have the turtle move to that location and make a dot. by using the dot0 function of turtle. Note that the tail is already up so it will not leave a line import turtle import math import random wn turtle.Screen0 wn.setworldcoordinates(-1,-1,1,1) fred- turtle.TurtleO fred.up0 numdaats 50 for i in range(numdarts) randx random.random0 randy random.randomO wn.exitonclick0 Throwing Darts Now that we have our dartboard setup, we can throw darts. We will assume that we are good enough at throwing darts that we always hit the wood. However, sometimes the darts will hit the dartboard and sometimes they will miss In order to simulate throwing the darts, we can generate two random numbers between zero and one. The first will be the x coordinate" of the dart and the second will be the "y coordinate" However, we have a problem. The coordinates for the dartboard go from -1 to 1 How can we turn a random number between 0 to 1 into a random number between -1 and 1? We know that random.randomO will retum a number between 0 and 1. We may obtain a number between-1 and 1by calculating random.random0 *2 -1 Activity 4: The program has been started for you. You need to fill in the part that will throw the dart" Once you know the x,y coordinate, have the turtle move to that location and make a dot. by using the dot0 function of turtle. Note that the tail is already up so it will not leave a line import turtle import math import random wn turtle.Screen0 wn.setworldcoordinates(-1,-1,1,1) fred- turtle.TurtleO fred.up0 numdaats 50 for i in range(numdarts) randx random.random0 randy random.randomO wn.exitonclick0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!