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-7.を解いてみる。
3.11-7.
コード(BBEdit)
sample7.py
#!/usr/bin/env python3 #-*- coding: utf-8 -*- def average_3(grade1, grade2, grade3): return (grade3 + grade2 + grade3) / 3 def average_top3(grade1, grade2, grade3, grade4): return max(average_3(grade1, grade2, grade3), average_3(grade1, grade2, grade4), average_3(grade1, grade3, grade4), average_3(grade2, grade3, grade4)) if __name__ == '__main__': print(average_top3(1, 2, 3, 4)) print(average_3(2, 3, 4))
入出力結果(Terminal, IPython)
$ ./sample7.py 3.6666666666666665 3.6666666666666665 $
0 コメント:
コメントを投稿