2013年4月16日火曜日

開発環境

『初めてのPython 第3版』(Mark Lutz 著、夏目 大 訳、オライリー・ジャパン、2009年、ISBN978-4-87311-393-7) のVI部(クラスとオブジェクト指向プログラミング)のまとめ演習9.(「死んだオウム」のスケッチ (芝居のシミュレーション))を解いてみる。

その他参考書籍

9.(「死んだオウム」のスケッチ (芝居のシミュレーション))

コード(BBEdit)

sample.py

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

class Scene:
    def __init__(self):
        self.customer = Customer()
        self.clerk = Clerk()
        self.parrot = Parrot()
    def action(self):
        self.customer.line()
        self.clerk.line()
        self.parrot.line()

class Actor:
    def line(self):
        print(self.says())

class Customer(Actor):
    def says(self):
        return "customer: \"that's one ex-bird!\""
        
class Clerk(Actor):
    def says(self):
        return "clerk: \"no it isn't…\""

class Parrot(Actor):
    def says(self):
        return "parrot: {0}".format(None)

if __name__ == '__main__':
    Scene().action()

入出力結果(Terminal)

$ ./sample.py
customer: "that's one ex-bird!"
clerk: "no it isn't…"
parrot: None
$

0 コメント:

コメントを投稿