您的位置:首页 > 编程语言 > Python开发

python 笔记 练习、加深记忆 《笨办法学Python》习题24 ——12.29

2017-12-29 13:48 585 查看
习题 24:  更多练习
目标与感悟:

•熟悉语法

•衔接、叠加的使用

•要有美学眼光

•码代码不能懒,不要复制,要手打,当然,可以使用notepad++的脚本来查异

 

ex24.py

#-*-coding:utf-8-*-
#python的易用性,单引号和双引号区别不大,但是如果在句子使用已经用的引号要进行转义符\
#其实完全可以这样写:print "You'd need to know 'bout
escapes with\\ that do \n newlines  and \ttabs."
print
"Let's practice everything."
print
'You\'d need to know \'bout escapes with \\ that do \nnewlines  and \t tabs.'
 
#回顾3引号,就是划定范围。
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
 
#定义函数,命名、参数、算法、返回结果。在我心中就4个步骤
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)[/b]
 
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
 
#变量,改变的量,都是临时的,以最新的算法为准,一开始start_point是10000,此处为1000
 
print
"We can also do that this way:"
print
"We'd have %d beans, %d jars, and %d crates."
%secret_formula(start_point)

运行结果:



另外说下notepad++的一个脚本,用于查异,不同会标色很强大很喜欢。
compare




内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐