]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
all Long constants have an L suffix, not l;
authorGuido van Rossum <guido@python.org>
Mon, 31 Aug 1992 10:54:17 +0000 (10:54 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 31 Aug 1992 10:54:17 +0000 (10:54 +0000)
added an output() function to move the I/O out of the algorithm

Demo/scripts/pi.py

index 74a66a7a471c6161a862a1ccdefd1b3b012c9c40..832aedc3110ea5f94bc53790668c311fa76f6980 100755 (executable)
 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()