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)、Code Magnet(p.117)を解いてみる。
Code Magnet(p.117)
コード(BBEdit)
sample97,.py
#!/usr/bin/env python3
#-*- coding: utf-8
highest_score = 0
result_f = open('results.txt')
for line in result_f:
score = float(line)
if score > highest_score:
highest_score = score
result_f.close()
print('The highest score was: {0}'.format(highest))
入出力結果(Terminal)
$ ./sample117.py
Traceback (most recent call last):
File "./sample117.py", line 7, in <module>
score = float(line)
ValueError: could not convert string to float: 'Johnny 8.65 \n'
$
0 コメント:
コメントを投稿