笨办法24更多练习

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了笨办法24更多练习相关的知识,希望对你有一定的参考价值。

源代码如下:

 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更多练习的主要内容,如果未能解决你的问题,请参考以下文章

笨办法学Python(二十五)

笨办法学python3练习代码ex21.py

笨办法学python3练习代码ex18.py

笨办法学python3练习代码ex19.py

笨办法学习python3练习代码:argv参数变量与文件操作

笨办法学python3代码练习ex23.py 字符串字节串字符编码