Practical Programming
An Introduction to Computer Science
Using Python 3
(Pragmatic Programmers)
(Pragmatic Bookshelf)
Paul Gries (著) Jennifer Campbell (著)
Jason Montojo (著) Lynn Beighley (編集)
開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python 3.4 (プログラミング言語)
Practical Programming: An Introduction to Computer Science Using Python 3 (Pragmatic Programmers) (Paul Gries (著)、Jennifer Campbell (著)、Jason Montojo (著)、Lynn Beighley (編集)、Pragmatic Bookshelf)のChapter 12(Designing Algorithms)、12.4(Exercises) 1-a, b, c.を解いてみる。
12.4(Exercises) 1-a, b, c.
コード(BBEdit)
sample1.py
#!/usr/bin/env python3 #-*- coding: utf-8 -*- # a. 省略 # b. 元の値は変更されない # c. def complement(dna): ''' finding the complement of a DNA sequence >>> dna = 'AATTGCCGT' >>> complement(dna) 'TTAACGGCA' >>> dna 'AATTGCCGT' ''' result = '' d = dict(A='T', T='A', G='C', C='G') for ch in dna: result += d[ch] return result if __name__ == '__main__': import doctest doctest.testmod()
入出力結果(Terminal, IPython)
$ ./sample1.py -v Trying: dna = 'AATTGCCGT' Expecting nothing ok Trying: complement(dna) Expecting: 'TTAACGGCA' ok Trying: dna Expecting: 'AATTGCCGT' ok 1 items had no tests: __main__ 1 items passed all tests: 3 tests in __main__.complement 3 tests in 2 items. 3 passed and 0 failed. Test passed. $
0 コメント:
コメントを投稿