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 8(Storing Collections of Data Using Lists)、8.9(Exercises) 8.を解いてみる。
8.9(Exercises) 8.
コード(BBEdit)
sample8.py
#!/usr/bin/env python3 #-*- coding: utf-8 -*- def is_longer(L1, L2): """ (list, list) -> bool Return True if and only if the length of L1 is longer than the length of L2 >>> is_longer([1, 2, 3], [4, 5]) True >>> is_longer(['abcdef'], ['ab', 'cd', 'ef']) False >>> is_longer(['a', 'b', 'c'], [1, 2, 3]) False """ return len(L1) > len(L2) if __name__ == '__main__': import doctest doctest.testmod()
入出力結果(Terminal, IPython)
$ ./sample8.py -v Trying: is_longer([1, 2, 3], [4, 5]) Expecting: True ok Trying: is_longer(['abcdef'], ['ab', 'cd', 'ef']) Expecting: False ok Trying: is_longer(['a', 'b', 'c'], [1, 2, 3]) Expecting: False ok 1 items had no tests: __main__ 1 items passed all tests: 3 tests in __main__.is_longer 3 tests in 2 items. 3 passed and 0 failed. Test passed. $
0 コメント:
コメントを投稿