《笨办法学 python3》系列练习计划——24.更多练习
2018-03-21 17:51
357 查看
题目
据说我们来到 24 题就已经距离第一部分的结束不远了。我们学习了如何打印%和转义字符
\,我们也已经能够写一些函数
def,并且知道如何把写好的脚本引入当前脚本
import……Zed 认为我们还需要练习来巩固学过的知识,我想不会有人觉得更多的练习不好,那么本题将是一个比较长的练习,据说下一题也是。
加分练习
检测、倒着检测、朗读代码、用注释理清思路。这些我们很熟悉了。故意写错一些代码,看看会有什么样的错误,确定自己能够修正它们。
我的答案
24.0 基础练习 + 24.1 注释
# 开场问候一下 print("Let's practice everything.") # 转义字符练习,这里还有一个英文口语知识点啊 -_-||| 'bout == about print('You\'d need to know \'bout escapes with \\ that do \nnewlines and \t tabs.') # 有不熟悉的知识点么? 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("-" * 15) # 变量 five = 10 - 2 + 3 - 6 # 格式化字符 print("This should be five: %s" % five) # 函数来了,还悄悄高速我们如何 return 多个值 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) 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 print("We can also do that this way:") # 更厉害了,直接在格式化字符的时候使用调用函数并把返回的值解包个格式化字符 print("We'd have %d beans, %d jars, and %d crates." % secret_formula(start_point))
返回目录
《笨办法学 python3》系列练习计划——目录相关文章推荐
- 《笨办法学 python3》系列练习计划——7. 更多打印
- 《笨办法学 python3》系列练习计划——17.更多文件操作
- 《笨办法学 python3》系列练习计划——36.设计和调试
- 《笨办法学 python3》系列练习计划——23.读代码
- 《笨办法学 python3》系列练习计划——32: 循环和列表
- 《笨办法学 python3》系列练习计划——31.作出决定
- 《笨办法学 python3》系列练习计划——37.复习各种符号
- 《笨办法学 python3》系列练习计划——13: 参数、解包、变量
- 《笨办法学 python3》系列练习计划——12.提示别人 input() 打印提示
- 《笨办法学 python3》系列练习计划——28.布尔表达式练习
- 《笨办法学 python3》系列练习计划——5. 格式化字符串
- 《笨办法学 python3》系列练习计划——16.读写文件
- 《笨办法学 python3》系列练习计划——29.如果 if
- 《笨办法学 python3》系列练习计划——1. 第一个程序 print() 练习
- 《笨办法学 python3》系列练习计划——22.总集篇、回忆篇。
- 《笨办法学 python3》系列练习计划——33.while循环
- 《笨办法学 python3》系列练习计划——9. 打印,打印,打印
- 《笨办法学 python3》系列练习计划——0. 序言、目录
- 《笨办法学 python3》系列练习计划——34.访问列表的元素
- 《笨办法学 python3》系列练习计划——11. 提问 input() 练习