在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ Python/ exercise24. 更多的練習
附錄 A-練習 9:生成一個空文件(Touch, New-Item)
附錄 A-練習 10:復制文件 (cp)
exercise44.繼承 Vs.包含
附錄 A-練習 14:刪除文件 (rm)
附錄 A-練習 11:移動文件 (mv)
exercise46.項目骨架
附錄 A-練習 3:如果你迷路了
exercise37.復習符號
exercise47.自動化測試
exercise3.數(shù)字和數(shù)學計算
附錄 A-練習 1:安裝
exercise32.循環(huán)和列表
exercise31.做出決定
exercise42.對象、類、以及從屬關系
exercise48.更復雜的用戶輸入
下一步
簡介
附錄 A-練習 7:刪除路徑 (rmdir)
exercise49.寫代碼語句
exercise18.命名, 變量, 代碼, 函數(shù)
exercise12.提示別人
exercise14.提示和傳遞
exercise40.模塊, 類和對象
附錄 A-練習 12:查看文件 (less, MORE)
exercise9.打印, 打印, 打印
exercise13.參數(shù), 解包, 變量
exercise30. Else 和 If
exercise28. 布爾表達式
附錄 A-練習 4:創(chuàng)建一個路徑 (mkdir)
附錄 A-練習 15:退出命令行 (exit)
exercise25. 更多更多的練習
exercise6.字符串和文本
exercise2.注釋和井號“#”
exercise21. 函數(shù)的返回值
附錄 A-下一步
exercise1.第一個程序
exercise23. 閱讀代碼
附錄 A-練習 5:改變當前路徑 (cd)
exercise17.更多文件操作
exercise24. 更多的練習
exercise19.函數(shù)和變量
exercise51.從瀏覽器獲取輸入
exercise22. 到目前為止你學到了什么?
exercise41.學會說面向?qū)ο?/span>
exercise52.開始你的 web 游戲
exercise20. 函數(shù)和文件
exercise15.讀文件
exercise45.你來制作一個游戲
exercise10.那是什么?
exercise8.打印, 打印
exercise35.分支和函數(shù)
exercise26. 恭喜你,可以進行一次考試了
exercise33.while 循環(huán)
exercise29. IF 語句
exercise36.設計和調(diào)試
exercise0.安裝和準備
exercise50.你的第一個網(wǎng)站
附錄 A-練習 2:路徑, 文件夾, 名錄 (pwd)
exercise38.列表操作
附錄 A-練習 6:列出當前路徑 (ls)
exercise16.讀寫文件
exercise4.變量和命名
exercise34.訪問列表元素
exercise11.提問
exercise43.基本的面向?qū)ο蟮姆治龊驮O計
附錄 A-簡介
附錄 A-練習 8:目錄切換(pushd, popd)
來自老程序員的建議
exercise27. 記住邏輯
exercise5.更多的變量和打印
exercise7.更多的打?。ㄝ敵觯?/span>
附錄 A-練習 13:輸出文件 (cat)
exercise39.字典,可愛的字典

exercise24. 更多的練習

你離這本書第一部分的結尾已經(jīng)不遠了,你應該已經(jīng)具備了足夠的 Python 基礎知識,可以繼續(xù)學習一些編程的原理了,但你應該做更多的練習。這個練習的內(nèi)容比較長,它的目的是鍛煉你的毅力,下一個習題也差不多是這樣的,好好完成它們,做到完全正確,記得仔細檢查。

print "Let's practice everything."
print 'You\'d need to know \'bout escapes with \\ that do \n newlines and \t tabs.'

poem = """
\tThe lovely world
with logic so firmly planted
cannot discern \n the needs of love
nor comprehend passion from intuition
and requires an explanation
\n\t\twhere there is none.
"""

print "--------------"
print poem
print "--------------"

five = 10 - 2 + 3 - 6
print "This should be five: %s" % five

def secret_formula(started):
    jelly_beans = started * 500
    jars = jelly_beans / 1000
    crates = jars / 100
    return jelly_beans, jars, crates

start_point = 10000
beans, jars, crates = secret_formula(start_point)

print "With a starting point of: %d" % start_point
print "We'd have %d beans, %d jars, and %d crates." % (beans, jars, crates)

start_point = start_point / 10

print "We can also do that this way:"
print "We'd have %d beans, %d jars, and %d crates." % secret_formula(start_point)

你看到的結果

$ python ex24.py
Let's practice everything.
You'd need to know 'bout escapes with \ that do
 newlines and   tabs.
--------------

       The lovely world
with logic so firmly planted
cannot discern
 the needs of love
nor comprehend passion from intuition
and requires an explanation

              where there is none.

--------------
This should be five: 5
With a starting point of: 10000
We'd have 5000000 beans, 5000 jars, and 50 crates.
We can also do that this way:
We'd have 500000 beans, 500 jars, and 5 crates.

附加題

1.記得仔細檢查結果,從后往前倒著檢查,把代碼朗讀出來,在不清楚的位置加上注釋。 2.故意把代碼改錯,運行并檢查會發(fā)生什么樣的錯誤,并且確認你有能力改正這些錯誤。

常見問題

Q:為什么在后面你把 jelly_beans 這個變量叫做 beans?

這是函數(shù)如何工作的一部分。記住,在函數(shù)中,變量都是臨時的.當你返回一個變量的時候,你可以把它賦值給另一個變量。我只是定義了一個叫做‘beans’的新變量去接收返回值。

Q:你所說的反向閱讀代碼是什么意思?

從最后一行開始閱讀。對比你的代碼和我的是不是一樣。如果確認一樣,向上移動一行閱讀,直到你讀到腳本的第一行為止。

Q:那首詩是誰寫的?

我寫的。