Commit c2015ece by BellCodeEditor

save project

parent f3194c94
Showing with 29 additions and 2 deletions
#定义英雄类
class Hero:
\ No newline at end of file
#定义属性
def __init__(self,name,health,attack):#名称,血量,攻击力
self.hp=health
self.level=1
self.attack=attack
self.name=name
#定义类方法
def upgrade(self):
self.level+=1
self.hp+=50
self.attack+=10
#实例化对象
yase=Hero('亚瑟',300,20)
houyi=Hero('后裔',250,30)
#修改属性
houyi.upgrade()
#测试
print(yase.attack)
print(houyi.attack)
\ No newline at end of file
print(' '+'1')
\ 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