Question: For the working code below(please run and look at result) adapt thePython code to automatically detect if a needle is crossing a line. If a

For the working code below(please run and look at result) adapt thePython code to automatically detect if a needle is crossing a line.

If a needle crosses, the code should return True, if it does not cross, return False.

Code;

import turtle import random

boardWidth = 40 needleLength = 30 numberOfNeedles = 50 myPen = turtle.Turtle() myPen.hideturtle() myPen.speed(0)

y=180 #Draw floor boards for i in range(0,10): myPen.penup() myPen.goto(-200,y) myPen.pendown() myPen.goto(200,y) y-=boardWidth

#Draw Needles myPen.color("#f442d1") for needle in range(0,numberOfNeedles): x=random.randint(-180,180) y=random.randint(-180,180) angle=random.randint(0,360) myPen.penup() myPen.goto(x,y) myPen.setheading(angle) myPen.pendown() myPen.forward(needleLength) print("L = " + str(needleLength)) print("N = " + str(numberOfNeedles)) print("W = " + str(boardWidth)) print("C = ???")

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!