码迷,mamicode.com
首页 > 其他好文 > 详细

笨办法24更多练习

时间:2017-10-11 18:16:06      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:结果   lines   rom   int   class   secret   lov   tab   bsp   

源代码如下:

 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更多练习

标签:结果   lines   rom   int   class   secret   lov   tab   bsp   

原文地址:http://www.cnblogs.com/p36606jp/p/7651740.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!