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.139)を解いてみる。
Sharpen your pencil(p.139)
コード(BBEdit)
sample139,.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)) # scores.sort() # scores.reverse() scores.sort(reverse=True) print('the top 3 scores') print(scores[0], scores[1], scores[2], sep='\n')
入出力結果(Terminal)
$ ./sample139.py the top 3 scores 9.12 8.65 8.45 $
0 コメント:
コメントを投稿