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-10.を解いてみる。
3.11-10.
コード(BBEdit)
sample8.py
#!/usr/bin/env python3 #-*- coding: utf-8 -*- def square(num): return num * num if __name__ == '__main__': for num in range(10): print('square({0}) -> {1}'.format(num, square(num)))
入出力結果(Terminal, IPython)
$ ./sample10.py square(0) -> 0 square(1) -> 1 square(2) -> 4 square(3) -> 9 square(4) -> 16 square(5) -> 25 square(6) -> 36 square(7) -> 49 square(8) -> 64 square(9) -> 81 $
0 コメント:
コメントを投稿