習題 7: 更多列印
現在我們将做一批練習,在練習的過程中你需要鍵入代碼,并且讓它們運作起來。我不會解釋太多,因為這節的内容都是以前熟悉過的。這節練習的目的是鞏固你學到的東西。我們幾個練習後再見。不要跳過這些習題。不要複制粘貼!python2:
print "Mary had a little lamb." print "Its fleece was white as %s." % 'snow' print "And everywhere that Mary went." print "." * 10 # what'd that do?
end1 = "C" end2 = "h" end3 = "e" end4 = "e" end5 = "s" end6 = "e" end7 = "B" end8 = "u" end9 = "r" end10 = "g" end11 = "e" end12 = "r"
# watch that comma at the end. try removing it to see what happens
print end1 + end2 + end3 + end4 + end5 + end6,print end7 + end8 + end9 + end10 + end11 + end12
你應該看到的結果:

Python3的代碼:
此處建議一定要先自己手打一遍再看我的代碼,對于Python3來說,列印的變動還是比較大的。如果你手打出的代碼執行時報錯了,請先自己試試排查錯誤
print ("Mary had a little lamb.")print ("Its fleece was white as %s." % 'snow')print ("And everywhere that Mary went.")print ("." * 10) # what't that do?
end1 = "C"end2 = "h"end3 = "e"end4 = "e"end5 = "s"end6 = "e"end7 = "B"end8 = "u"end9 = "r"end10 = "g"end11 = "e"end12 = "r"
# watch that comma at the end. try removing it to see what happensprint (end1 + end2 +end3 + end4 + end5 + end6,end7 + end8 + end9 + end10 + end11 + end12)
輸出的結果為:
有沒有發現什麼差別?(當然,也有可能是我打錯了。。。)
加分習題
接下來幾節的加分習題是一樣的。
1. 逆向閱讀,在每一行的上面加一行注解。
2. 倒着朗讀出來,找出自己的錯誤。
3. 從現在開始,把你的錯誤記錄下來,寫在一張紙上。
4. 在開始下一節習題時,閱讀一遍你記錄下來的錯誤,并且盡量避免在下個練習中再犯同樣的錯誤。
加群交流在背景回複“加群”,添加小編微信,小編拉你進去猜您喜歡往期精選▼笨辦法學 Python--跟書練習一
笨辦法學 Python--跟書練習二
笨辦法學 Python--跟書練習三
笨辦法學 Python--跟書練習四~變量(variable)和命名
笨辦法學 Python--跟書練習五~更多的變量和列印
笨辦法學 Python--跟書練習六~字元串(string)和文本
小白學 Python(1):開篇
小白學 Python(2):基礎資料類型(上)
小白學 Python(3):基礎資料類型(下)
小白學 Python(4):變量基礎操作
Python安裝及環境配置
END
更多資源盡在星球,背景回複“星球”擷取優惠