[Python-checkins] CVS: python/dist/src/Demo/scripts pi.py,1.5,1.6
Moshe Zadka
moshez@users.sourceforge.net
Tue, 20 Feb 2001 08:13:45 -0800
Update of /cvsroot/python/python/dist/src/Demo/scripts
In directory usw-pr-cvs1:/tmp/cvs-serv21023
Modified Files:
pi.py
Log Message:
Changed to use the fact that str(long) doesn't produce a trailing L
Reindented
Index: pi.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Demo/scripts/pi.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** pi.py 1996/11/27 19:47:04 1.5
--- pi.py 2001/02/20 16:13:43 1.6
***************
*** 12,33 ****
def main():
! k, a, b, a1, b1 = 2L, 4L, 1L, 12L, 4L
! while 1:
! # Next approximation
! 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
! while d == d1:
! 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()
--- 12,33 ----
def main():
! k, a, b, a1, b1 = 2L, 4L, 1L, 12L, 4L
! while 1:
! # Next approximation
! 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
! while d == d1:
! 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 str() to avoid the 'L'
! sys.stdout.write(str(d))
! # Flush so the output is seen immediately
! sys.stdout.flush()
main()