2019年11月19日火曜日

学習環境

代数への出発 (新装版 数学入門シリーズ) (松坂 和夫(著)、岩波書店)の第2章(整式の計算)、3(展開公式)の問16の解答を求めてみる。



    1. 9.92=99102=100-12100=10000-200+1100=9801100=98.01

    2. 903·897=900+3900-3=810000-9=809991

    3. 523+483=50+23+50-23=2503+3·50·4=2·50502+12=251200

コード

#!/usr/bin/env python3
from sympy import symbols, pprint
from unittest import TestCase, main

print('16.')


class MyTest(TestCase):

    def test(self):
        spam = [9.9**2, 903 * 897, 52 ** 3 + 48 ** 3]
        egg = [98.01, 809991, 251200]
        for s, t in zip(spam, egg):
            self.assertEqual(s, t)


if __name__ == '__main__':
    main()

入出力結果(Zsh、cmd.exe(コマンドプロンプト)、Terminal、Jupyter(IPython))

% ./sample16.py -v
16.
test (__main__.MyTest) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.000s

OK
%

0 コメント:

コメントを投稿