開発環境
- macOS Mojave - Apple (OS)
- Emacs (Text Editor)
- Windows 10 Pro (OS)
- Visual Studio Code (Text Editor)
- Python 3.7 (プログラミング言語)
Practical Programming: An Introduction to Computer Science Using Python 3.6 (Paul Gries(著)、Jennifer Campbell(著)、Jason Montojo(著)、Pragmatic Bookshelf)のChapter 5(Making Choices)、Exercises 1の解答を求めてみる。
コード
Python 3
#!/usr/bin/env python3 from unittest import TestCase, main class MyTestCase(TestCase): def setUp(self): pass def tearDown(self): pass def test(self): spam = [(True and not False, True), (True or True and False, True), (not True or not False, True), (True and not 0, True), (52 < 52.3, True), (1 + 52 < 52.3, False), (4 != 4.0, False)] for i, (a, b) in enumerate(spam): self.assertEqual(a, b) def test_b(self): with self.assertRaises(NameError): print(True and not false) if __name__ == '__main__': main()
入出力結果(Bash、cmd.exe(コマンドプロンプト)、Terminal、Jupyter(IPython))
$ ./sample1.py .. ---------------------------------------------------------------------- Ran 2 tests in 0.000s OK $
0 コメント:
コメントを投稿