diff options
author | Guido van Rossum <guido@python.org> | 1992-08-31 10:54:17 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1992-08-31 10:54:17 (GMT) |
commit | 0b2b440a13ee1b9c0719e246ae4ec08a8efd5519 (patch) | |
tree | c30683d9cca67644da3233e9944842f30a8c12e1 /Demo/scripts/pi.py | |
parent | 0cc19450e27ffacf4c70ac8717d6ecb000a4d4e1 (diff) | |
download | cpython-0b2b440a13ee1b9c0719e246ae4ec08a8efd5519.zip cpython-0b2b440a13ee1b9c0719e246ae4ec08a8efd5519.tar.gz cpython-0b2b440a13ee1b9c0719e246ae4ec08a8efd5519.tar.bz2 |
all Long constants have an L suffix, not l;
added an output() function to move the I/O out of the algorithm
Diffstat (limited to 'Demo/scripts/pi.py')
-rwxr-xr-x | Demo/scripts/pi.py | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/Demo/scripts/pi.py b/Demo/scripts/pi.py index 74a66a7..832aedc 100755 --- a/Demo/scripts/pi.py +++ b/Demo/scripts/pi.py @@ -11,20 +11,23 @@ import sys def main(): - k, a, b, a1, b1 = 2l, 4l, 1l, 12l, 4l + k, a, b, a1, b1 = 2L, 4L, 1L, 12L, 4L while 1: # Next approximation - p, q, k = k*k, 2l*k+1l, k+1l + p, q, k = k*k, 2L*k+1L, k+1L a, b, a1, b1 = a1, b1, p*a+q*a1, p*b+q*b1 # Print common digits d, d1 = a/b, a1/b1 - #print a, b, a1, b1 while d == d1: - # Use write() to avoid spaces between the digits - sys.stdout.write(`int(d)`) - # Flush so the output is seen immediately - sys.stdout.flush() - a, a1 = 10l*(a%b), 10l*(a1%b1) + output(d) + a, a1 = 10L*(a%b), 10L*(a1%b1) d, d1 = a/b, a1/b1 +def output(d): + # Use write() to avoid spaces between the digits + # Use int(d) to avoid a trailing L after each digit + sys.stdout.write(`int(d)`) + # Flush so the output is seen immediately + sys.stdout.flush() + main() |