![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python初学笔记
DMU_lzq1996
这个作者很懒,什么都没留下…
展开
-
字符串;变量;输入输出
print("Program 'Game Over.'")print("Same","message","as before.")print("Just", "a bit", "bigger.")print(原创 2018-10-04 15:15:21 · 225 阅读 · 0 评论 -
对象组合,扩展类,方法重写
#对象的组合class Card(object): """A playing card.""" RANKS = ["A","2","3","4","5","6","7","8","9","10","J","原创 2018-10-16 22:24:19 · 204 阅读 · 0 评论 -
读写txt文件;数据序列化;异常处理
#读取文本文件print("Opening and closing the file.")text_file = open("read_it.txt","r")text_file.close()print("\nReading characters from the file.")text_file = open("read原创 2018-10-09 16:39:41 · 533 阅读 · 0 评论 -
棋盘游戏
#全局变量X = "X"O = "O"EMPTY = " "TIE = "TIE"NUM_SQUARES = 9def display_instruct(): """Display game instruction.""&原创 2018-10-08 08:55:30 · 811 阅读 · 0 评论 -
直接访问私有变量@
#客户端读取修改私有变量@#创建属性class Critter(object): """A virtual pet""" def __init__(self,name): print("A new critter has been born!") self.__name = name @property def name(self...原创 2018-10-14 11:08:07 · 194 阅读 · 0 评论 -
字典{}
#创建字典geek = {"404":"clueless.From the web error message 404,meaning page not found.", "Gooling":"searching the Internet for background information on a person.", &原创 2018-10-07 10:47:07 · 114 阅读 · 0 评论 -
列表【】
#列表inventory = ["sword","armor","shield","heading potion"]print("Your items:")for item in inventory: print(item)#列表长度print(len(inventory))#in操作if &原创 2018-10-06 18:54:04 · 134 阅读 · 0 评论 -
元组()
# 创建新的字符串message = input("Enter a message:")new_message = ""VOWELS = "aeiou"print()for letter in message: if letter.lower() not in VOWELS: new_message += letter print(原创 2018-10-06 11:49:30 · 181 阅读 · 0 评论 -
for循环;range,len函数;in操作符
#for循环word = input("Enter a word:")print("\nHere's each letter in your word:")for letter in word: print(letter) Enter a word:lzqHere's each letter in your word:lzq#range函数print(&qu原创 2018-10-05 17:13:24 · 2051 阅读 · 0 评论 -
随机函数;if-else和while
# 随机数的生成import randomdie1 = random.randint(1,6)die2 = random.randrange(6) + 1total = die1 + die2print("You rolled a %d and a %d for a total of %d"%(die1,die2,total))You rolled a 5 and a 4 ...原创 2018-10-05 11:13:06 · 169 阅读 · 0 评论 -
类对象;私有变量
#类及对象class Critter (object): """A virtual pet""" def talk(self): print("Hi,I'm instance of class Critter.") crit = Critter()crit.talk()Hi,I'm instance of class Critter.#构...原创 2018-10-12 10:49:35 · 143 阅读 · 0 评论 -
问答游戏
import sysdef open_file(file_name,mode): """Open a file.""" try: the_file = open(file_name,mode) except IOError as e: print("Unable to open the file",file_name,"Ending pr...原创 2018-10-12 10:48:20 · 161 阅读 · 0 评论 -
类型转换;运算符
#逻辑错误print(""" Trust Fund BuddyTotals your monthly spending so that your trust fund doesn't run out(and you're forced to get a real job)Please enter the requested,monthly costs.Since ...原创 2018-10-04 17:14:39 · 185 阅读 · 0 评论 -
21点卡牌游戏
1.游戏玩法游戏流程ER图:类关系图:2.基础类设计2.1 Card类功能:表示卡牌特性的类方法:init:初始化卡牌特性:花色,大小,正负str:rep返回正面卡牌的花色大小flip:改变正负2.2 Hand类功能:表示玩家手上的卡牌特性及操作方法:init:初始化手中卡牌为空列表str:rep返回手中的卡牌花色大小clear:清空手中卡牌(列表设为空)ad...原创 2018-10-21 10:27:06 · 1572 阅读 · 0 评论