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 2(textual data: Every string has its place)、Code Magnets(p.61)を解いてみる。
Code Magnets(p.61)
コード(BBEdit)
sample61.py
#!/usr/bin/env python3 #-*- coding: utf-8 -*- import urllib.request price = 99.99 while price > 4.74: page = urllib.request.urlopen('http://beans-r-us.appspot.com/prices.html') text = page.read().decode('utf8') where = text.find('>$') start_of_price = where + 2 end_of_price = where + 6 price = text[start_of_price:end_of_price] print('Buy!')
入出力結果(Terminal)
$ ./sample61.py Traceback (most recent call last): File "./sample61.py", line 7, in <module> while price > 4.74: TypeError: unorderable types: str() > float() $
0 コメント:
コメントを投稿