Jun-29-2018, 12:19 PM
Hey guys, I'm new to python but I do need it for a simulation that I must use for a school project. I have come across a simulation http://www.101computing.net/estimating-p...ns-needle/ that I need to use but I'm unable to complete Task 2. Could you help me out? The code from the simulation is as follows:
Your Python script should then count how many needles are crossing a line and use this to estimate a value of Pi.
Please. I really need some help.
#Estimating Pi using Buffon's Needle # www.101compiting.net/estimating-pi-using-buffons-needle import turtle import random import math boardWidth = 40 needleLength = 30 numberOfNeedles = 10 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))The task is : Adapt this Python script to automatically detect if a needle is crossing a line.
Your Python script should then count how many needles are crossing a line and use this to estimate a value of Pi.
Please. I really need some help.