December 2, 200520 yr i wrote a short code in python to find pi and this is what i got. import math l = 0 n = 0 z = 0 pi = 0 p = 0 t = 0 t = input("how long do you want the program to run?: ") while l < t: l = l + 1 n = n + 1 p = p + 1/n**2 z = p * 6 pi = math.sqrt(z) print pi print l print n print z print "pi" print p print t result how long do you want the program to run?: 7 2.44948974278 7 7 6 pi 1 7 last time i looked pi != 2.44948974278 however i did it on my calcilatior and found an answer very very close to pi so i figure if i continue it will continue getting closer. what i found was 2.44948974278**2 = 6 python is rounding thewhile l < t: l = l + 1 n = n + 1 p = p + 1/n**2 section to p = 1 the right answers should be simular topi = 3.14159 z = 9.8696 p = 1.6449 thank you
December 2, 200520 yr So is this a problem? Or do you want recognition for this amazing less-than-20-lines program? What's the point of this post, exactly? :?
December 2, 200520 yr Author no im asking if anyone can help me fix the problem with python rounding. i guess not then
December 2, 200520 yr python.org would have a much better equipped community to put that question to :) I don't think there would be many people on this forum that even know what python is.
December 4, 200520 yr no im asking if anyone can help me fix the problem with python rounding. i guess not then I don't know python very well, but shouldn't you set a double/single data type on those variables? I'd be guessing their integers at the moment :) Sharper's right though, a python forum would be a better place.
Create an account or sign in to comment