Home i need help converting this program into a while loop from for loop with python 2.7
Reply: 0

i need help converting this program into a while loop from for loop with python 2.7

user711
1#
user711 Published in May 21, 2018, 3:02 am

convert this for loop into a while loop finding pi

import turtle
import math
import random

t = turtle.Turtle()
wn = turtle.Screen()
wn.setworldcoordinates(-400,-400,400,400)

t.pu()
t.speed(0)
t.goto(0,-400)
t.pd()
t.color("green")
t.circle(400)
t.color("red")
hits=0.0
numdarts = 100
for i in range(numdarts):
    randx = random.uniform(-1,1)
    randy = random.uniform(-1,1)
    if (randx**2+ randy**2)<1:
        hits+=1.0

    t.pu()
    t.goto(400*randx,400*randy)
    t.pd()
    t.dot()
print 4*(hits/numdarts)
wn.exitonclick()

want to use a while loop instead to estimate the value of pi, given the acceptable amount of error for the approximation

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.275236 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO