Commit 98db3cea by BellCodeEditor

save project

parent cec87a77
Showing with 37 additions and 17 deletions
class hero: # class hero:
def __init__(self,name,hp,attack): # def __init__(self,name,hp,attack):
self.level = 1 # self.level = 1
self.name = name # self.name = name
self.hp=hp # self.hp=hp
self.attack=attack # self.attack=attack
def shenji(self): # def shenji(self):
self.hp=self.hp+50 # self.hp=self.hp+50
self.level=self.level+1 # self.level=self.level+1
self.attack=self.attack+4 # self.attack=self.attack+4
yase=hero("yase",300,200) # yase=hero("yase",300,200)
yase.shenji() # yase.shenji()
print(yase.hp) # print(yase.hp)
houyi = hero("后裔",200,400) # houyi = hero("后裔",200,400)
houyi.shenji() # houyi.shenji()
# print(houyi.hp)
# 创建一个cat类 每一只猫都有名字(name),年龄(age),性别(sex)
# 每一只猫都有吃东西的行为(print("猫在吃饭")).实例化出一只名字为aa,年龄为10,性别为男的猫 并在控制台打印猫在吃饭
class cat:
def __init__(self,name,age,sex,hungry):
self.name=name
self.age = age
self.sex = sex
self.hungry = hungry
def eat(self):
self.hungry=self.hungry-1
a = cat("cat1",11,"man",5)
b = cat("cat2",11,"man",5)
a.eat()
a.name = "a猫"
print(a.name)
print(b.hungry)
print(houyi.hp)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment