開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python 3.4 (プログラミング言語)
Head First C ―頭とからだで覚えるCの基本(David Griffiths (著)、Dawn Griffiths (著) 中田 秀基(監訳)(翻訳)、木下 哲也 (翻訳)、オライリージャパン)の6章(データ構造と動的メモリ: 架け橋を築く)、自分で考えてみよう(p.289)をpythonで考えてみる。
自分で考えてみよう(p.289)
コード(BBEdit, Emacs)
sample289.py
#!/usr/bin/env python3
#-*- coding: utf-8 -*-
class Island:
def __init__(self, name, opens, closes, next=None):
self.name = name
self.opens = opens
self.closes = closes
self.next = next
@staticmethod
def display(start):
while start:
print('名前:{0}\n 営業時間:{1}-{2}'.format(
start.name, start.opens, start.closes))
start = start.next
if __name__ == '__main__':
start = None
next = None
i = None
while True:
try:
name = input()
except Exception:
break
next = Island(name, '09:00', '17:00')
if not start:
start = next
i = start
else:
i.next = next
i = next
Island.display(start)
入出力結果(Terminal, IPython)
$ ./sample289.py < sample289.txt 名前:デルフィーノ島 営業時間:09:00-17:00 名前:エンジェル島 営業時間:09:00-17:00 名前:ヤマネコ島 営業時間:09:00-17:00 名前:ネリの島 営業時間:09:00-17:00 名前:グレートトッディ 営業時間:09:00-17:00 $ cat sample289.txt デルフィーノ島 エンジェル島 ヤマネコ島 ネリの島 グレートトッディ $
0 コメント:
コメントを投稿