Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

OpenStack Trove

Authors: Amrith Kumar, Douglas Shelley

1st Edition

1484212215, 9781484212219

More Books

Students also viewed these Databases questions

Question

Discuss the Rights issue procedure in detail.

Answered: 1 week ago

Question

Discuss the Rights issue procedure in detail.

Answered: 1 week ago

Question

Explain the procedure for valuation of shares.

Answered: 1 week ago

Question

Which months of this year 5 Mondays ?

Answered: 1 week ago

Question

Define Leap year?

Answered: 1 week ago

Question

Provide examples of KPIs in Human Capital Management.

Answered: 1 week ago

Question

What are OLAP Cubes?

Answered: 1 week ago