Again from tonight's class prep.

Such scripts might be useful exhibits if you're still trying to get
approval to move beyond a TI calculator in math class.  Playing with
extended precision helps bring the concepts of limits and convergence alive.

My students are employed adults so winning such approval is a non-issue.
But then I ask them to imagine themselves back in school, with Python a
tool of choice in math class.  Wouldn't that have been great!?

Kirby



# -*- coding: utf-8 -*-
"""
Created on Thu Dec  3 16:40:46 2015

See:  http://www.miniwebtool.com/first-n-digits-of-e/?number=300

@author: kurner

LAB:

Write a unittest to confirm convergence to e to 300 places.
after n steps.
"""

import unittest

from decimal import *

def euler(n):
    n = Decimal(n)
    one = Decimal(1)
    return (one + one/n) ** n

class Test_e(unittest.TestCase):

    def test_outcome(self):
        expected = ('2.718281828459045235360287471352662'
                    '49775724709369995957496696762772407'
                    '66303535475945713821785251664274274'
                    '66391932003059921817413596629043572'
                    '90033429526059563073813232862794349'
                    '07632338298807531952510190115738341'
                    '87930702154089149934884167509244761'
                    '46066808226480016847741185374234544'
                    '2437107539077744992069')
        with localcontext() as c:
            c.prec = 400
            result = euler('1' + '0' * 301)

        self.assertEqual(str(result)[:len(expected)], expected)

if __name__ == "__main__":
    unittest.main()
_______________________________________________
Edu-sig mailing list
Edu-sig@python.org
https://mail.python.org/mailman/listinfo/edu-sig

Reply via email to