Head First Programming
A learner's guide to programming
using the Python language
( O'Reilly Media; )
David Griffiths (著) Paul Barry (著)
開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python (プログラミング言語)
Head First Programming A learner's guide to programming using the Python language (David Griffiths(著)、Paul Barry(著)、 O'Reilly Media; )のChapter 5(hashes and databases - Putting data in its place)、Sharpen your pencil(p.161)を解いてみる。
Sharpen your pencil(p.161)
コード(BBEdit)
sample161.py
#!/usr/bin/env python3 #-*- coding: utf-8 line="101;Johnny 'wave-boy' Jones;USA;8.32;Fish;21" d = {} d['ID'], d['Name'], d['Country'], d['Average'], d['Board type'], d['Age'] \ = line.split(';') for key in ['ID', 'Name', 'Country', 'Average', 'Board type', 'Age']: print('{0:11s} {1}'.format(key + ':', d[key]))
入出力結果(Terminal)
$ ./sample161.py ID: 101 Name: Johnny 'wave-boy' Jones Country: USA Average: 8.32 Board type: Fish Age: 21 $
0 コメント:
コメントを投稿