pi.py 354 B

1234567891011121314151617181920
  1. #! /usr/local/bin/python3
  2. def divide(int):
  3. "Does the actual calculation"
  4. return 4.0 / (int * (int + 1) * (int + 2))
  5. answer = 3.0
  6. c = 2
  7. i = 1
  8. while c < 1000000:
  9. if i % 2 == 0:
  10. answer = answer - divide(c)
  11. print answer
  12. c += 2
  13. else:
  14. answer = answer + divide(c)
  15. print answer
  16. c += 2
  17. i += 1