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
目标与感悟:
•熟悉语法
•衔接、叠加的使用
•要有美学眼光
•码代码不能懒,不要复制,要手打,当然,可以使用notepad++的脚本来查异
ex24.py
#-*-coding:utf-8-*-
#python的易用性,单引号和双引号区别不大,但是如果在句子使用已经用的引号要进行转义符\
#其实完全可以这样写:print "You'd need to know 'bout
escapes with\\ that do \n newlines and \ttabs."
"Let's practice everything."
'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 poem
"---------------"
#回顾变量
five
=10
-2
+3
- 6
"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]
"With a starting point of: %d "
%start_point
"We'd have %d beans, %d jars, and %d crates."
%(beans,jars,
crates)
start_point
= start_point
/ 10
#变量,改变的量,都是临时的,以最新的算法为准,一开始start_point是10000,此处为1000
"We can also do that this way:"
"We'd have %d beans, %d jars, and %d crates."
%secret_formula(start_point)
运行结果:
另外说下notepad++的一个脚本,用于查异,不同会标色很强大很喜欢。
compare
相关文章推荐
- python 笔记 python编译器初识以及split() 、pop()的使用 《笨办法学Python》习题25 ——12.29
- python 笔记 基础知识回顾 《笨办法学Python》习题22 ——12.29
- python 笔记 布尔表达式练习 《笨办法学Python》习题28 ——1.2
- python 笔记 if语句的简单使用 《笨办法学Python》习题29 ——1.2
- python 笔记 函数和文件(seek和readline)《笨办法学Python》习题20 ——12.28
- python 笔记 循环和列表 《笨办法学Python》习题32 ——1.6
- 本方法学python 习题24(综合练习) 习题25(更多关于函数和变量的练习)习题26(修改程序)
- Python学习笔记: 第五章课后习题练习
- 笨方法学习Python-习题24: 更多练习
- 笨方法学Python 习题 24: 更多练习
- python 笔记 小试身手 修正代码 《笨办法学Python》习题26 ——12.31
- python 笔记 真和假的逻辑关系 《笨办法学Python》习题27 ——12.31
- python 笔记 return的使用 《笨办法学Python》习题21 ——12.28
- python 笔记 While 循环 《笨办法学Python》习题33 ——1.7
- python 笔记 序数和基数《笨办法学Python》习题34 ——1.16
- python 笔记 分支和函数《笨办法学Python》习题35 ——1.17
- python 笔记 if语句中的elif和else 《笨办法学Python》习题30 ——1.2
- 《笨办法学Python》习题24:更多练习
- python 笔记 if语句的简单嵌套 《笨办法学Python》习题31 ——1.3
- python 笔记 函数(function)浅识 (《笨办法学Python》习题18)——12.26