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 5(Making Choices)、5.6(Exercises) 4.を解いてみる。
5.6(Exercises) 4.
コード(BBEdit)
sample4.py
#!/usr/bin/env python3
#-*- coding: utf-8 -*-
# my friend is right.
def turn_camera_on():
print('turn camera on')
def f(x, y):
if x or y:
if not (x and y):
turn_camera_on()
def g(x, y):
if x != y:
turn_camera_on()
for x, y in [(x, y) for x in [True, False] for y in [True, False]]:
print(x, y)
f(x, y)
g(x, y)
入出力結果(Terminal, IPython)
$ ./sample4.py True True True False turn camera on turn camera on False True turn camera on turn camera on False False $
0 コメント:
コメントを投稿