Commit 4b940ba8 by BellCodeEditor

save project

parent 22354288
Showing with 18 additions and 0 deletions
class Hero: #创建类
def __init__(self,name,hp,attack): #定义一个方法
self.level = 1 #等级为1
self.name = name #英雄的名字
self.hp = hp #英雄的血量
self.attack = attack #英雄的攻击力
def uprade(self): #定义一个升级函数
self.level += 1 #等级+1
self.hp += 50 #血量+50
self.attack += 5 #攻击力+5
houyi = Hero('后羿',240,23) #创建houyi英雄
houyi.uprade() #houyi升级
print('等级:',houyi.level) #等级为...
print('血量:',houyi.hp) #血量为...
print('攻击力:',houyi.attack) #攻击力为...
\ 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