開発環境
- macOS Catalina - Apple (OS)
- Emacs (Text Editor)
- Windows 10 Pro (OS)
- Visual Studio Code (Text Editor)
- Python 3.8 (プログラミング言語)
Practical Programming: An Introduction to Computer Science Using Python 3.6 (Paul Gries(著)、Jennifer Campbell(著)、Jason Montojo(著)、Pragmatic Bookshelf)のChapter 12(Designing Algorithms)、Exercise 1の解答を求めてみる。
コード
#!/usr/bin/env python3
from unittest import TestCase, main
from typing import Dict
print('1-a, b, c.')
class TestComplement(TestCase):
def test(self):
s = 'AATTGCCGT'
self.assertEqual(complement(s), 'TTAACGGCA')
self.assertEqual(complement(complement(s)), s)
def complement(dna_sequence: str) -> str:
d = {'A': 'T', 'T': 'A', 'G': 'C', 'C': 'G'}
return ''.join([d[c] for c in dna_sequence])
if __name__ == "__main__":
main()
入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))
% ./sample1.py -v
1-a, b, c.
test (__main__.TestComplement) ... ok
----------------------------------------------------------------------
Ran 1 test in 0.000s
OK
%
0 コメント:
コメントを投稿