[Edu-sig] Programming challenge:
Kirby Urner
kurner at oreillyschool.com
Sat Mar 12 03:52:27 CET 2011
"=== makingmath.py ==="
"""
"make math your own"
-- Maria Droujkova
"""
def makepi():
"""stub function
Ramanujan's freakish formula
http://worldgame.blogspot.com/2008/02/reflective-fragment.html
"""
# using_gmpy()
# using_decimal()
# using_whatever()
return 3.14
"=== test_pi.py ==="
"OST programming challenge (more on FB)"
import unittest
import makingmath
approx_pi = """3\
.141592653589793238462643383279502884197169399375
1058209749445923078164062862089986280348253421170
6798214808651328230664709384460955058223172535940
8128481117450284102701938521105559644622948954930
3819644288109756659334461284756482337867831652712
0190914564856692346034861045432664821339360726024
9141273724587006606315588174881520920962829254091
7153643678925903600113305305488204665213841469519
4151160943305727036575959195309218611738193261179
3105118548074462379962749567351885752724891227938
1830119491298336733624406566430860213949463952247
3719070217986094370277053921717629317675238467481
8467669405132000568127145263560827785771342757789
6091736371787214684409012249534301465495853710507
9227968925892354201995611212902196086403441815981
3629774771309960518707211349999998372978049951059
7317328160963185950244594553469083026425223082533
4468503526193118817101000313783875288658753320838
1420617177669147303598253490428755468731159562863
8823537875937519577818577805321712268066130019278
76611195909216420198
""".replace("\n","")
class Test4Pi(unittest.TestCase):
def test_thousand_digits(self):
self.assertEquals(makingmath.makepi(), approx_pi, "Oops!")
def _test():
print(approx_pi)
if __name__ == "__main__":
# _test()
unittest.main( )
More information about the Edu-sig
mailing list