[Tutor] Please critique my Fraq.py (original) (raw)

Gregor Lingl glingl at aon.at
Mon Jul 19 20:08:30 CEST 2004


Dick Moores schrieb:

Tutors,

This may seem like a silly script to write. But it's just an exercise I set for myself. And it does compute that amazingly close approximation to PI, 355/113: I won't criticize your script, I just (for fun) checked your result in a quick and dirty manner, and indeed:

from math import pi min([(abs(float(p)/q-pi)100/pi,p,q) for q in range(2,200) for p in range(3q, int(3.2*q))]) (8.4913678767406097e-006, 355, 113)

the next fraction which approximates pi better seems to be

min([(abs(float(p)/q-pi)100/pi,p,q) for q in range(2,16717) for p in range(int(3.14q), int(3.15*q))]) (8.4738311605107342e-006, 52163, 16604)

Regards, Gregor



More information about the Tutor mailing list