Skip to Content
深入淺出程式設計
book

深入淺出程式設計

by David Griffiths, Paul Barry
August 2011
Intermediate to advanced
444 pages
8h 55m
Chinese
GoTop Information, Inc.
Content preview from 深入淺出程式設計
62 第二章
各得其所
程式碼磁貼解答
增加新功能的程式碼散落在冰箱門上,你的任務是重新安排這些
磁貼,讓程式不斷循環,直到咖啡豆的價格降到 $4.74 或以下。
import urllib.request
while price > 4.74:
page = urllib.request.urlopen("http://www.beans-r-us.biz/prices.html")
text = page.read().decode("utf8")
where = text.find(‘>$’)
end_of_price = start_of_price + 4
start_of_price = where + 2
price = text[start_of_price:end_of_price]
print ("Buy!")
price = 99.99
是否記得
縮排這幾
行?它們
位在新增
的迴圈下
面。
這一行不應該縮排,
因為它位在迴圈以外。
ch02.indd 62 2011/8/6 上午 02:22:08
目前位置 4 63
文字資料
將新版程式碼增加到 IDLE 的編輯視窗裡,並且執行它。
看起來好像有問題,TypeEr ror 的意思係蝦咪?發生蝦咪代誌?
這是你輸入
IDLE 的程式碼。
這係蝦咪?
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Kubernetes设计模式

Kubernetes设计模式

Bilgin Ibryam, Roland Huß
深入淺出代數

深入淺出代數

Tracey Pilone, Dan Pilone
Kafka权威指南(第2版)

Kafka权威指南(第2版)

Gwen Shapira, Todd Palino, Rajini Sivaram, Krit Petty

Publisher Resources

ISBN: 9789862762691