本书课后练习题代码:
http://download.csdn.net/detail/gongzaiwenzi/8009071
本书英文PDF版本:
http://www.open-open.com/doc/view/1033ad2f0a0845e8aab0e9abab2b5a7f
第三章 字符串、列表、元祖和字典 1、用“”或者‘’来输入字符串,并用print输出 2、列表中加上和删去元素
>>> wizard_list=['a','b'] >>> print(wizard_list) ['a', 'b'] >>> wizard_list.append('bear') >>> print(wizard_list) ['a', 'b', 'bear'] >>> del wizard_list[2] >>> print(wizard_list) ['a', 'b']3、元祖是用括号()表示的列表,与列表的主要区别在于创建之后不能做改动。 4、字典里每一个元素都有KEY—对应的VALUE 5、逗号输出自动变成空格
num_house=3 num_wuding=25 num_didao=2 num_didaos=40 print("忍者数量等于:",num_house*num_wuding) print("武士数量等于:",num_didao*num_didaos*num_house) 输出结果: 忍者数量等于: 75 武士数量等于: 240第四章 用海龟画图 1.注意:Pen 中P一定要大写
>>> import turtle >>> t=turtle.Pen() 一些指令 >>> t.forward(50) >>> t.forward(50) >>> t.back(50) >>> t.left(90) >>> t.forward(50) >>> t.left (90) >>> t.forward(50) >>> t.reset()**//清空画布** >>> t.back(50) >>> t.up()//抬起画笔 >>> t.left (90) >>> t.forward(50) >>> t.right (90) >>> t.down()//放下画笔 >>> t.forward (50)第五章 用if和else来提问 1.python中的空白是有意义的,处于同一位置的代码代表同一个代码块。 只要新起了一行(前面的留白不同),就代表一个新的代码块。[外链图片转存中…(img-swhxU3K3-1569659281514)] 2.if-else 代码示例
>>> age=10 >>> if age==10: print("1") else: print("2")3.elif==else if
>>> age=10 >>> if age==12: print("1") elif age==10: print("2") else: print("3")4.字符串与数字之间的相互转换 int/float(字符串)变成数字 str(数字)变成字符串
第六章 循环
>>> for i in range(0,5): print("hello") hello hello hello hello hello2.第二种用法
>>> wizard_list=['you','me','he','she'] >>> for i in wizard_list: print(i) you me he she >>>表示对于 wizard_list里的每个元素,放入变量i,然后打印,直到执行完列表
3.Python语言中的嵌套循环结构,代码如下
for i in wizard_list: print(i) for j in wizard_list: print(j) you you me he she me you me he she he you me he she she you me he she第七章 使用函数和模块来重用你的代码 1.定义函数–调用函数–参数赋值–计算得出结果
>>> def hanshu1(canshu1): print("hello %s"