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 4(data in files and arrays: Sort it out)、Sharpen your pencil(p.133)を解いてみる。
Sharpen your pencil(p.133)
コード(BBEdit)
sample133,.py
#!/usr/bin/env python3 #-*- coding: utf-8 scores = [] with open('results.txt') as result_f: for line in result_f: name, score = line.split() scores.append(float(score)) print('the first 3 scores') print(scores[0], scores[1], scores[2], sep='\n')
入出力結果(Terminal)
$ ./sample133.py the first 3 scores 8.65 9.12 8.45 $
0 コメント:
コメントを投稿