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 3(Designing and Using Functions)、3.11-8.を解いてみる。
3.11-8.
コード(BBEdit)
sample8.py
#!/usr/bin/env python3 #-*- coding: utf-8 -*- def weeks_elapsed(day1, day2): """ >>> weeks_elapsed(8, 5) 0 >>> weeks_elapsed(40, 61) 3 """ return abs(day1 - day2) // 7 if __name__ == '__main__': for day1, day2 in [(3, 20), (20, 3), (8, 5), (40, 61)]: print(weeks_elapsed(day1, day2))
入出力結果(Terminal, IPython)
$ ./sample8.py 2 2 0 3 $
0 コメント:
コメントを投稿