学習環境
- Surface
- Windows 10 Pro (OS)
- Nebo(Windows アプリ)
- iPad
- MyScript Nebo - MyScript(iPad アプリ(iOS))
- 参考書籍
代数への出発 (新装版 数学入門シリーズ) (松坂 和夫(著)、岩波書店)の第1章(実数)、練習問題7の解答を求めてみる。
コード
Python 3
#!/usr/bin/env python3
from sympy import symbols, pprint, sqrt, Rational
from unittest import TestCase, main
print('7.')
x = 1 / (sqrt(5) - sqrt(3))
y = 1 / (sqrt(5) + sqrt(3))
class MyTest(TestCase):
def setUp(self):
pass
def tearDown(self):
pass
def test(self):
spam = [x + y, x * y, x ** 2 + x * y + y ** 2, y / x + x / y]
egg = [sqrt(5), Rational(1, 2), Rational(9, 2), 8]
for s, t in zip(spam, egg):
self.assertEqual(s.simplify(), t)
if __name__ == '__main__':
main()
入出力結果(Zsh、cmd.exe(コマンドプロンプト)、Terminal、Jupyter(IPython))
% ./sample7.py -v 7. test (__main__.MyTest) ... ok ---------------------------------------------------------------------- Ran 1 test in 0.322s OK %
0 コメント:
コメントを投稿