
python
杰少2020
这个作者很懒,什么都没留下…
展开
-
python第十二章十三章十四章项目-外星人入侵游戏源码
python编程外星人入侵游戏源码(有兴趣需要的同学,记得在评论区留言或点赞、收藏下~~)视频演示的是教材python编程 从入门到实践的游戏 外星人入侵 在教材基础上做了三处改动:1,开始画面按Play时,减去一条命,显示2个飞船+正在玩的一共3个,改进常规合理性;2,分数和等级,添加文本描述,界面不至于单调只有数字;3,一局结束(三条命都挂掉)弹出Play again按钮 教材中依然是Play 提高交互性。...原创 2020-07-28 22:22:15 · 345 阅读 · 6 评论 -
Python 第十一章 测试类
Python 第十一章 测试类1 提供一个类class AnonymousSurvey():“”“收集匿名调查问卷的答案”""def init(self,question):“”“存储一个问题,并为存储答案做准备”""self.question=questionself.responses=[]def show_questions(self): """显示调查问卷""" print(self.question)def store_response(self原创 2020-07-26 00:34:33 · 543 阅读 · 0 评论 -
python第十章 文件和异常
python第十章 文件和异常圆周率中包含你的生日吗filename=‘pi_million_digits.txt’with open(filename) as file_project:lines=file_project.readlines()pi_string=’’for line in lines:pi_string+=line.strip()birthday=input("Enter your birthday,in the form mmddyy: ")if birthday原创 2020-07-25 22:18:15 · 517 阅读 · 0 评论 -
Python第9章 类
Python第9章 类根据类创建实例class Dog():“”“一次模拟小狗的简单完成”""def init(self,name,age):“”“初始化属性name和age”""self.name=nameself.age=agedef sit(self): """模拟小狗被命令时蹲下""" print(self.name.title()+" is now sitting.")def roll_over(self): """模拟小狗被命令时打滚""" p原创 2020-07-25 12:09:47 · 377 阅读 · 0 评论 -
python第8章函数的整理
8.3.4 结合使用函数和while循环def get_formatted_name(first_name,last_name):“”“显示整洁的姓名”""full_name=first_name+’ '+last_namereturn full_namewhile True:print("\nPlease tell me your name: ")print(“enter ‘q’ at any time to quit”)f_name=input("First name: ")if f_原创 2020-07-23 23:16:06 · 362 阅读 · 0 评论 -
Geany编写python错误解决SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0xa3
python编写循环的结束语句后编译报错:SyntaxError: (unicode error) ‘utf-8’ codec can’t decode byte 0xa3解决方法:“文档’中的文件编码设置,将unicode设置(点击)为utf-8,如截图...原创 2019-06-17 22:37:00 · 2095 阅读 · 1 评论 -
在Geany中编译Python的注释方法,程序开头添加#coding:utf-8
在Geany中编译Python时注释:1.如果注释中含有中文,只需要在程序的开始位置添加 # coding:utf-8如下#coding:utf-8chars=["a","b","c"]for s in chars:#print前需要加 tab 键 (此行为注释的话) print(s) 2 如果注释中没有中文,开头可以不用添加 # coding:utf-8...原创 2019-06-17 22:07:42 · 916 阅读 · 0 评论 -
python删除小结
1 使用del语句删除元素例 del 列表[索引]知道要删除元素的索引。删除后无法访问该元素。2 使用pop()方法删除chars=[“a”,“b”,“c”] //后面以此列表作变量使用ch=chars.pop() //删除(弹出)最后一个元素,并将该元素保存到变量ch中可以使用ch访问删除的元素。3 弹出列表中任何位置的元素ch2=chars.pop(索引)...原创 2019-06-16 21:34:00 · 152 阅读 · 0 评论 -
Python之禅
在交互式解释器中输入import this就会显示 Tim Peters 的 “The Zen of Python”The Zen of Python, by Tim PetersPython之禅,蒂姆•彼得斯Python之父—Guido van RossumBeautiful is better than ugly.//优美胜于丑陋(Python以编写优美的代码为目标)Explic...原创 2019-06-16 20:51:02 · 132 阅读 · 0 评论 -
python PEP8 编码规范(格式设置指南)
原文网站链接:http://python.org/dev/peps/pep-0008/原创 2019-06-19 23:49:03 · 1068 阅读 · 0 评论 -
python开发:如何通过pip安装pygame,如何下载pip压缩包以及安装pygame
这里介绍如何通过pip安装pygame,并利用Geany编辑器导入pygame,运行弹出一个窗口案例。建议通过命令窗口由pip安装,具体步骤如下:1,首先下载pip并安装:下载地址:https://pip.pypa.io/en/latest/installing/如图:点击链接get-pip.py,进入页面后,如果没有自动弹出下载窗口,那么会是浏览器页面文字显示模式,一定要等页面加载完...原创 2019-06-18 21:38:11 · 4977 阅读 · 5 评论