開発環境
- macOS Catalina - 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 7(Using Methods)、Exercises 1の解答を求めてみる。
コード
Python 3
#!/usr/bin/env python3
from unittest import TestCase, main
print('1.')
class MyTestCase(TestCase):
def test(self):
egg = [('hello'.upper(), 'HELLO'),
(('Happy Birthday').lower(), 'happy birthday'),
('WeeeEEEEeeeEEEEeee'.swapcase(), 'wEEEeeeeEEEeeeeEEE'),
('ABC123'.isupper(), True),
('aeiouAEIOU'.count('a'), 1),
('hello'.endswith('o'), True),
('hello'.startswith('H'), False),
('Hello {0}'.format('Python'), 'Hello Python'),
('Hello {0}! Hello {1}!'.format(
'Python', 'World'), 'Hello Python! Hello World!')]
for s, t in egg:
self.assertEqual(s, t)
if __name__ == '__main__':
main()
入出力結果(Zsh、cmd.exe(コマンドプロンプト)、Terminal、Jupyter(IPython))
% ./sample1.py 1. . ---------------------------------------------------------------------- Ran 1 test in 0.000s OK %
0 コメント:
コメントを投稿