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

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.random( will return a number between 0 and 1. We may obtain a number between -1 and 1by calculating random.random() *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 dot 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.Screen() wn.setworldcoordinates(-1,-1,1,1) fred = turtle.Turtle() fred.up0 numdats = 50 for i in range(numdarts): randx=random.random randy = random.random() x= y= wn.exitonclick()

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

More Books

Students also viewed these Databases questions

Question

LO2 Explain the major laws governing employee compensation.

Answered: 1 week ago