python: object
"""
Peson.py
人类类
edit:
ide:
date:
"""
class Human(object):
"""
人类类
"""
#限制对象属性只能是SLOTS里面的变量名 对象绑定属性,不用先定义属性
#__slots__ = ('sage','sname','sfrom')
sage=0 #年龄
sname="geovindu" #名字
sfrom="from china"
def __init__(self,name, age,frm):
"""
:param name:
:param age:
"""
self._name=name
self._age=age
self._frm=frm
def sleeep(self):
"""
睡觉
:return: none
"""
print(id(self))
print(self._age,"岁的",self._name,'在睡觉')
def eat(self):
"""
吃饭
:return: none
"""
print(id(self))
print(self._age,"岁的",self._name,"在吃饭")
def instrudce(self):
"""
自我介绍
:return: none
"""
print(f"{self._age}岁的{self._name}自我介绍:{self._frm}")
def operateAllFunc(self):
"""
处理所有方法
:return: none
"""
self.sleeep()
self.eat()
self.instrudce()
调用:
p=Peson.Human("geovindu",20,"我是中国人")
print(id(p)) #打印内存地址
p.sage=20
p.sname="涂聚文"
p.operateAllFunc()
print(p.sname)
p2=Peson.Human("涂聚文",30,"我是江西人")
print(id(p2))#打印内存地址
p2.operateAllFunc()
"""
HealthSpah.py
运动减肥类
edit:geovindu,Geovin Du
date:20230618
IDE:PyCharm 2023.1.2
"""
class Spa(object):
"""
体重减肥计量类
"""
def __init__(self,name,weight):
"""
:param name: 姓名
:param weight: 体重
"""
self._name=name
self._weight=weight
self._num=0 #记录跑步次数
self._enum=0 #记录吃饭次数
def joggin(self):
"""
跑步
:return:none
"""
self._weight-=0.5
self._num+=1
print(f"{self._name}运动第:{self._num}次,体重减至{self._weight} KG")
def eat(self):
"""
吃饭
:return:none
"""
self._weight+=1
self._enum+=1
print(f"{self._name}吃饭第{self._enum}次之后,体重为:{self._weight}KG")
def __str__(self):
return f"{self._name}运动第:{self._num}次,吃饭第{self._enum}次之后,体重为:{self._weight}KG"
调用:
h=HealthSpah.Spa('小明',70)
h.joggin()
h.joggin()
h.eat()
h.joggin()
print(h)
小明运动第:1次,体重减至69.5 KG 小明运动第:2次,体重减至69.0 KG 小明吃饭第1次之后,体重为:70.0KG 小明运动第:3次,体重减至69.5 KG 小明运动第:3次,体重减至69.5 KG,吃饭第1次之后,体重为:69.5KG
"""
HealthSpah.py
运动减肥类
edit:geovindu,Geovin Du
date:20230618
IDE:PyCharm 2023.1.2
构造函数(方法)--析构函数(方法)
构造方法:创建
析构方法:销毁前
"""
class Spa(object):
"""
体重减肥计量类
"""
def __init__(self,name,weight):
"""
构造方法
:param name: 姓名
:param weight: 体重
"""
self._name=name
self._weight=weight
self._num=0 #记录跑步次数
self._enum=0 #记录吃饭次数
def __del__(self):
"""
析构方法
:return:
"""
print(f"{self._name}挂机了")
def joggin(self):
"""
跑步
:return:none
"""
self._weight-=0.5
self._num+=1
print(f"{self._name}运动第:{self._num}次,体重减至{self._weight} KG")
def eat(self):
"""
吃饭
:return:none
"""
self._weight+=1
self._enum+=1
print(f"{self._name}吃饭第{self._enum}次之后,体重为:{self._weight}KG")
def __str__(self):
return f"{self._name}运动第:{self._num}次,吃饭第{self._enum}次之后,体重为:{self._weight}KG"
del h #手动删除
# 不挂机
while True:
pass
"""
HealthSpah.py
运动减肥类
edit:geovindu,Geovin Du
date:20230618
IDE:PyCharm 2023.1.2
构造函数(方法)--析构函数(方法)
构造方法:创建
析构方法:销毁前
"""
class Spa(object):
"""
体重减肥计量类
"""
cout=0 #类属性,计算多少个类调用
"""
类属性
"""
def __init__(self,name,weight):
"""
构造方法
:param name: 姓名
:param weight: 体重
"""
self._name=name #实例属性
self._weight=weight #实例属性
self._num=0 #记录跑步次数
self._enum=0 #记录吃饭次数
Spa.cout+=1
def __del__(self):
"""
析构方法
:return:
"""
print(f"{self._name}挂机了")
def joggin(self):
"""
跑步
:return:none
"""
self._weight-=0.5
self._num+=1
print(f"{self._name}运动第:{self._num}次,体重减至{self._weight} KG")
def eat(self):
"""
吃饭
:return:none
"""
self._weight+=1
self._enum+=1
print(f"{self._name}吃饭第{self._enum}次之后,体重为:{self._weight}KG")
@classmethod
def showCount(cls):
"""
类方法
:return: none
"""
print(f"一个创建了Spa类共{cls.cout}次")
@staticmethod
def showinfo():
"""
静态方法
:return:
"""
print(f"肚子饿了")
def __str__(self):
return f"{self._name}运动第:{self._num}次,吃饭第{self._enum}次之后,体重为:{self._weight}KG"
调用:
du=HealthSpah.Spa('涂聚文',70)
du.joggin()
du.joggin()
du.joggin()
du.eat()
du.joggin()
du.joggin()
print(du)
print(HealthSpah.Spa.cout)
print(HealthSpah.Spa.showCount())
print(HealthSpah.Spa.cout)
print(HealthSpah.Spa.showinfo())
"""
GameInfo.py
游戏玩家类
edit:geovindu,Geovin Du
date:20230618
IDE:PyCharm 2023.1.2
"""
import random
import sys
import os
class Game(object):
"""
游戏类
"""
def __init__(self,playerName):
"""
:param playerName:
"""
self._playerName=playerName
self._playerScore=0 #记录当前游戏分数
self._topScore=0 #历史最高分
self._tatoalScore=0 #总分数
self._num=0 #玩游戏次数
@staticmethod
def showHelp():
print("游戏帮助信息")
def showTopScore(self):
print(f"{self._playerName}玩了{self._num}次,历史最高分是:{self._topScore},总分是{self._tatoalScore}")
def startGame(self):
self._playerScore = random.randint(1,100)
if self._playerScore > self._topScore:
self._topScore = self._playerScore
self._tatoalScore += self._playerScore
self._num += 1
#print(f"{self._playerName}玩了{self._num}游戏,当前积分{self._playerScore}共计分{self._tatoalScore},最高分是:{self._topScore}")
def __str__(self):
return f"{self._playerName}玩了:{self._num}游戏,最后一次积分是:{self._playerScore}共计分:{self._tatoalScore},最高分是:{self._topScore}"
调用:
ga=GameInfo.Game("李明")
ga.startGame()
ga.startGame()
ga.startGame()
ga.startGame()
ga.showTopScore()
ga.showHelp()
print(ga)
输出:
游戏帮助信息 李明玩了4游戏,当前积分93共计分276,最高分是:93 小明运动第:1次,体重减至69.5 KG 小明运动第:2次,体重减至69.0 KG 小明吃饭第1次之后,体重为:70.0KG 小明运动第:3次,体重减至69.5 KG 小明运动第:3次,吃饭第1次之后,体重为:69.5KG 11 涂聚文运动第:1次,体重减至69.5 KG 涂聚文运动第:2次,体重减至69.0 KG 涂聚文运动第:3次,体重减至68.5 KG 涂聚文吃饭第1次之后,体重为:69.5KG 涂聚文运动第:4次,体重减至69.0 KG 涂聚文运动第:5次,体重减至68.5 KG 涂聚文运动第:5次,吃饭第1次之后,体重为:68.5KG 2 一个创建了Spa类共2次 None 2 肚子饿了
"""
GameInfo.py
游戏玩家类
edit:geovindu,Geovin Du
date:20230618
IDE:PyCharm 2023.1.2
"""
import random
import time
import sys
import os
class Game(object):
"""
游戏类
"""
topGamScrore=0 #
"""
类属性 最高分
"""
topGameName="" #
"""
类属生 最高分的玩家
"""
def __init__(self,playerName):
"""
构造方法
:param playerName:
"""
self._playerName=playerName
self._playerScore=0 #记录当前游戏分数
self._topScore=0 #历史最高分
self._topNmae=''
self._tatoalScore=0 #总分数
self._num=0 #玩游戏次数
def __del__(self):
print(f"{self._playerName}挂机了")
@staticmethod
def showHelp():
"""
帮助信息
:return:
"""
print(f"游戏帮助信息")
@staticmethod
def showTopScroe(cls):
"""
显示最高分数
:return:
"""
#print(f"{self._playerName}玩了{self._num}次,历史最高分是:{self._topScore},总分是{self._tatoalScore}")
print(f"历史最高分是:{cls.topGamScrore}")
def selfShowTopScore(self):
"""
:return:
"""
print(f"{self._playerName}玩了{self._num}次,历史最高分是:{self._topScore},总分是{self._tatoalScore}")
def startGame(self):
"""
开始玩游戏
:return:
"""
self._playerScore = random.randint(1,100)
if self._playerScore > self._topScore:
self._topScore = self._playerScore
self._topNmae=self._playerName
if self._playerScore >Game.topGamScrore:
Game.topGamScrore=self._playerScore
Game.topGameName=self._playerName
if self._playerScore==Game.topGamScrore:
Game.topGameName="相同分"
self._tatoalScore += self._playerScore
self._num += 1
time.sleep(3)
#print(f"{self._playerName}玩了{self._num}游戏,当前积分{self._playerScore}共计分{self._tatoalScore},最高分是:{self._topScore}")
def __str__(self):
"""
:return:
"""
return f"{self._playerName}玩了:{self._num}游戏,最后一次积分是:{self._playerScore}共计分:{self._tatoalScore},最高分是:{self._topScore}"
"""
StudentInfo.py
游戏玩家类
edit:geovindu,Geovin Du
date:20230618
IDE:PyCharm 2023.1.2
"""
class Student(object):
def __init__(self,name,age,skill):
self._name=name
self._age=age
self._skill=skill
def showActcion(self):
print(f"{self._name}表演才艺{self._skill}")
def showInfo(self):
print(f"大家好,我是{self._name},今年{self._age}岁,才艺{self._skill}")
def info(self):
self.showInfo()
self.showActcion()
def setName(self,name):
self._name=name
def getName(self):
return self._name
def setAge(self,age):
self._age=age
def getAge(self):
return self._age
def __str__(self):
return f"大家好,我是{self._name},今年{self._age}岁,才艺{self._skill}"
"""
TeachInfo.py
游戏玩家类
edit:geovindu,Geovin Du
date:20230618
IDE:PyCharm 2023.1.2
"""
import StudentINfo
class Teach(object):
"""
"""
def __init__(self,name):
"""
:param name:
:param studentName:
"""
self._name=name
self._student=None
def intruduce(self,student:StudentINfo.Student):
"""
:return:
"""
self._student=student
student.info()
#print(f"大家好,我是{student.getName()},今年{student.getAge()}岁")
def __str__(self):
return f"大家好,我是{self._student.getName()},今年{self._student.getAge()}岁"
stu=StudentINfo.Student("小明",18,"唱歌")
stu2=StudentINfo.Student("小军",17,"跳舞")
tea=TeachInfo.Teach("刘老师")
tea.intruduce(stu)
tea.intruduce(stu2)
print(tea)
print(stu.showActcion())
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)
浙公网安备 33010602011771号