1. 程式人生 > >笨辦法24更多練習

笨辦法24更多練習

ice 換行符 div rate ima rom beans where not

源代碼如下:

 1 #coding:utf-8
 2 
 3 print "Let‘s practice everything."
 4 print You\‘d need to know \‘bout escapes with \\ that do \n newlines and \t tabs.
 5 # 各種轉義
 6 poem = """
 7 \tThe lovely world
 8 with logic so firmly planted
 9 cannot discern \n the needs of love 
10 nor comprehend passion from intuition
11 and requires an explanation 12 \n\t\twhere there is none. 13 """ 14 # 制表符 15 # 換行符 16 17 print "--------------" 18 print poem 19 print "--------------" 20 21 five = 10 - 2 + 3 - 6 22 print "This should be five: %s" % five 23 24 def secret_formula(started): 25 jelly_beans = started * 500 26 jars = jelly_beans / 1000 27
crates = jars / 100 28 return jelly_beans, jars, crates 29 # 結果返回函數 30 start_point = 10000 31 beans, jars, crates = secret_formula(start_point) 32 # beans,jars,crates可以換成任意變量名 33 print "with a starting point of: %d" % start_point 34 print "We‘d have %d beans, %d jars, and %d crates." % (beans, jars, crates)
35 # 變量名也需要相應變更 36 start_point = start_point / 10 37 38 print "We can also do that this way:" 39 print "We‘d have %d beans, %d jars, and %d crates." % secret_formula(start_point)

輸出結果:

技術分享

笨辦法24更多練習