開発環境
- 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 8(Storing Collections of Data Using Lists)、Exercise 7の解答を求めてみる。
コード
#!/usr/bin/env python3
import doctest
def same_first_last(l: list) -> bool:
'''
>>> same_first_last([3, 4, 2, 8, 3])
True
>>> same_first_last(['apple', 'banana', 'pear'])
False
>>> same_first_last([4.0, 4.5])
False
'''
return l[0] == l[-1]
if __name__ == '__main__':
doctest.testmod()
入出力結果(Zsh、cmd.exe(コマンドプロンプト)、Terminal、Jupyter(IPython))
% ./sample7.py -v
Trying:
same_first_last([3, 4, 2, 8, 3])
Expecting:
True
ok
Trying:
same_first_last(['apple', 'banana', 'pear'])
Expecting:
False
ok
Trying:
same_first_last([4.0, 4.5])
Expecting:
False
ok
1 items had no tests:
__main__
1 items passed all tests:
3 tests in __main__.same_first_last
3 tests in 2 items.
3 passed and 0 failed.
Test passed.
%
0 コメント:
コメントを投稿