《Python编程从入门到实践》
Flerken101
github主页:https://github.com/Flerken101
展开
-
day3--注释及简单的用户输入输出
注释:单行注释用#;多行注释用三个单引号或三个双引号即’’‘被注释的内容’’’#预先设定一个年龄age1=120#让用户输入自己的姓名与年龄name=input(“your name:”)age=input(“your age:”)input接受的所有数据都是字符串,即便输入的是数字,依然会被当作字符串来处理#查看input接受的数据类型print(type(name),type(...原创 2019-04-21 23:59:06 · 87 阅读 · 0 评论 -
《Python编程从入门到实践》Chapter 6练习题
# 6-1 人information = {'first_name':'Julian','last_name':'Aaron','city':'New York'}print(information['first_name'])print(information['last_name'])print(information['city'])#6-3 编程词汇字典programmi...原创 2019-07-06 21:24:04 · 168 阅读 · 0 评论 -
《Python编程从入门到实践》Chapter 8练习题
#8-1 消息:编写一个名为display_message()的函数,它打印一个句子,指出你在本章学的是什么。#调用这个函数,确认显示的消息正确无误。def display_message(): print('\nIn Chapter 8, I learned how to define and use functions with ' 'Python.')di...原创 2019-07-18 00:31:45 · 1030 阅读 · 0 评论 -
关于Python 类的属性及其 方法的参数类型 的一些要点
class Car(): """一次模拟汽车的简单尝试""" def __init__(self, make, model, year=2016): """初始化描述汽车点的属性""" self.make = make self.model = model self.year = year self....原创 2019-07-21 00:00:40 · 969 阅读 · 0 评论 -
《Python编程从入门到实践》Chapter 15练习题
"""15-1 立方:数字的三次方被称为其立方。请绘制一个图形,显示前5个整数的立方值。再绘制一个图形,显示前面5000个整数的立方值。"""#前5个整数的立方值import matplotlib.pyplot as pltinput_value = [1,2,3,4,5]cubes = [1,8,27,64,125]plt.plot(input_value,cubes ,line...原创 2019-08-02 20:41:44 · 666 阅读 · 0 评论 -
《Python编程从入门到实践》Chapter 12~14:2D游戏《外星人入侵》源码
① alien_invasion.py② game_functions.py③ game_stats.py④ alien.py⑤ bullet.py⑥ ship.py⑦ scoreboard.py⑧ button.py⑨ settings.py原创 2019-07-31 01:46:53 · 520 阅读 · 0 评论 -
《Python编程从入门到实践》Chapter 9练习题
'''9-1参观:创建一个名为Restaurant的类,其方法__init__( )设置两个属性:restaurant_name 和cuisine_type.创建一个名为describe_restaurant()的方法和一个名为open_restaurant( )的方法,其中前者打印前述两项信息,而后者打印一条消息,指出餐馆正在营业。根据这个类创建一个名为restaurant 的实例, 分别...原创 2019-07-23 03:01:14 · 375 阅读 · 0 评论 -
《Python编程从入门到实践》Chapter 10练习题
open()函数的参数不止课本提到的两个,还有其他多个参数。而且不止open()函数,其他很多函数都是如此,以后还需要多多学习。'''10-1 Python学习笔记:在文本编辑器中新建一个文件, 写几句话来总结一下你至此学到的Python知识,其中每一行都以“In Python you can”打头。 将这个文件命名为learning_python.txt, 并将其存储到为完成本章练习而编...原创 2019-07-27 03:11:31 · 418 阅读 · 0 评论 -
《Python编程从入门到实践》Chapter 11练习题
'''11-1城市和国家:编写一个函数,它接受两个形参:一个城市名和一个国家名。这个函数返回一个格式为City, Country的字符串,如Santiago, Chile 。将这个函数存储在一个名为city_functions.py的模块中。创建一个名为test_cities.py的程序,对刚编写的函数进行测试(别忘了,你需要导入模块unittest 以及要测试的函数)。编写一个名为te...原创 2019-07-28 14:56:40 · 229 阅读 · 0 评论 -
《Python编程从入门到实践》Chapter 17练习题
#17.3 测试:在python_respos.py中,打印status_code的值,已核实API调用是否成功了。请编写一个名为test_python_repos.py的程序,它使用单元测试来断言status_code的值为200.想想你还可以做出哪些断言,如返回的条目数符合预期,仓库总数超过特定的值等。import unittestimport look_over_repository...原创 2019-08-09 06:59:22 · 526 阅读 · 0 评论 -
《Python编程从入门到实践》Chapter 5(5.1&示例5.2条件测试及练习题)
#5.1--if循环语句简单示例#结合for循环cars=['audi','bmw','subaru','toyota']for car in cars: if car=='bmw': print(car.upper()) else: print(car.title())#5.2条件测试#5.2.1检查是否相等#一个等号是陈述或定义(...原创 2019-06-30 16:44:57 · 615 阅读 · 0 评论 -
《Python编程从入门到实践》Chapter 4(4.4使用列表的一部分&4.5元组)
#4.4.1切片#python中多行注释用三对单引号或双引号表示,如下"""①输出列表的前三名成员②首先明白列表中元素索引的差一行为,其次要明白返回的是从第一个索引到第二个索引之前的元素,并不包含第二个索引处的元素(这一点同range函数相同,但range返回的是数字) 注意思考方式,这两点都要考虑到③输出结果也是一个列表"""players=['charles','martina'...原创 2019-06-30 00:32:33 · 98 阅读 · 0 评论 -
《Python编程从入门到实践》2.3字符串
print("hello world")#变量名mesage="hello Python"print(mesage)#拼接字符串及引号的应用famous_person="Albert Einstein"message="A person who never made a mistake never tried anything new."print(famous_person+"...原创 2019-06-21 22:34:01 · 81 阅读 · 0 评论 -
编写python代码时的注意事项及运行时的常见错误
1,名称错误。2,语法错误。3,类型错误。包括:字符串和数值类型错误;符号的使用错误,如括号与方括号。4,差一错误。多出现在列表的引用中...原创 2019-06-23 21:18:20 · 1632 阅读 · 0 评论 -
关于Pycharm的快捷键及某些状况的处理方式
1,不能换行:键盘insert2,撤销上一步:主菜单Edit | Undo 或者 键盘Ctrl+Z3,恢复上一步:主菜单Edit | Redo或者 键盘Ctrl+Shift+Z原创 2019-06-23 21:24:04 · 292 阅读 · 0 评论 -
《Python编程从入门到实践》Chapter 3
# @File : 3.1列表.py# @Software: PyCharmnumber=[1,2,3,"a ","b" ]print(number)print(number[0])print(number[1])print(number[4])print(number[-1].title())print(number[-2].rstrip())message="The...原创 2019-06-24 05:19:44 · 93 阅读 · 0 评论 -
这两段代码到底有什么不同?---第一段代码toppings对应的值列表中两种配料间没有加逗号,导致两种配料不会分行显示
pizza = { 'crust':'thick', 'toppings':['mushroom''extra cheese'], }#概述所点的比萨print("You ordered a " + pizza['crust'] + "-crust pizza"+ "with the following toppings:")for topping ...原创 2019-07-08 19:40:00 · 36 阅读 · 0 评论 -
《Python编程从入门到实践》Chapter 4(4.1&4.2)
#用for遍历整个列表,并进行一些操作magicians=['alice','david','carolina']for magician in magicians: print(magician) #注意缩进 print(magician.title()+",that was a great trick!") print("I can't wait to se...原创 2019-06-27 23:16:25 · 115 阅读 · 0 评论 -
《Python编程从入门到实践》Chapter 4(4.3&4.3练习题)
#使用range生成一系列数字#输出1至4的整数,差一行为导致只能输出到4(5-1)for value in range(1,5): print(value)#函数list可将一些列数字直接转化为列表number=list(range(1,6))print(number)#range函数指定步长#生成1到10之内的偶数列表(注意是列表要用list函数)even_num...原创 2019-06-27 23:26:09 · 267 阅读 · 0 评论 -
《Python编程从入门到实践》Chapter 5(5.3&5.4&5.5)
v原创 2019-07-03 19:48:12 · 186 阅读 · 0 评论 -
《Python编程从入门到实践》Chapter 7练习题
#7.1 汽车租赁message = input('Please tell me the kind of car you want to rent: ')print('Let me see if I can find you a '+ message.title() + '.')#7.2 餐馆订位number = input('How many do you have in your...原创 2019-07-13 18:13:02 · 319 阅读 · 0 评论 -
《Python编程从入门到实践》Chapter 16练习题
#16.2 比较锡卡特和死亡谷的气温import csvimport matplotlib.pyplot as pltfrom datetime import datetimefilename_v = "death_valley_2014.csv"with open(filename_v) as v: reader_v = csv.reader(v) header_r...原创 2019-08-07 18:34:23 · 463 阅读 · 0 评论