Commit 5f5df097 by BellCodeEditor

auto save

parent b43b2eb0
Showing with 23 additions and 0 deletions
class Hero:
def __init__(self, name, level, hp, attack):
# name, level, hp, attack 都是类的属性值
self.level = level
self.name = name
self.hp = hp
self.attack = attack
def upgrade(self):
self.level += 1
self.hp += 10
self.attack += 5
yase = Hero('亚瑟', 1, 200, 20)
houyi = Hero('后羿', 1, 150, 35)
print('亚瑟的攻击力是:', yase.attack)
print('后羿的攻击力是:', houyi.attack)
yase.upgrade()
houyi.upgrade()
print('亚瑟升级后的攻击力是:', yase.attack)
print('后羿升级后的攻击力是:', houyi.attack)
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