2014年7月26日土曜日

開発環境

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) 2.を解いてみる。

5.6(Exercises) 2.

コード(BBEdit)

sample2.py

#!/usr/bin/env python3
#-*- coding: utf-8 -*-

def a(x, y):
    if x and y:
        print('and')

def b(x, y):
    if not x:
        print('not')

def c(x, y):
    if x or y:
        print('or')

入出力結果(Terminal, IPython)

$ ipython
Python 3.4.1 (default, May 21 2014, 01:39:38) 
Type "copyright", "credits" or "license" for more information.

IPython 2.1.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: from sample2 import *

In [2]: x = True

In [3]: y = True

In [4]: a(x, y)
and

In [5]: x = False

In [6]: a(x, y)

In [7]: b(x, y)
not

In [8]: x = True

In [9]: b(x, y)

In [10]: c(x, y)
or

In [11]: y = False

In [12]: c(x, y)
or

In [13]: x
Out[13]: True

In [14]: y
Out[14]: False

In [15]: x = False

In [16]: c(x, y)

In [17]: quit()
$ 

0 コメント:

コメントを投稿