Commit cf4e99dd by BellCodeEditor

auto save

parent a2cc0669
Showing with 36 additions and 0 deletions
class Hero: # 类名,Hero表示英雄
def __init__(self, name, hp, attack): # 用关键字def定义一个 __init__方法,参数:(self)
self.level = 1 # 等级
self.name = name # 名字(类属性)
self.hp = hp # 生命(类属性)
self.attack = attack # 攻击力(类属性)
def ypgrade():
yase.level=yase.level+1
yese.hp=yase.hp+50
yase.attack=yase.attack+4
yase = Hero("亚瑟",300,20)
print("亚瑟的初始血量为: ",yase.hp)
upgrade()
upgrade()
print("升级2次后,亚瑟的血量为: ",yase.hp)
\ No newline at end of file
class Hero: # 类名,Hero表示英雄
def __init__(self, name, hp, attack): # 用关键字def定义一个 __init__方法,参数:(self)
self.level = 1 # 等级
self.name = name # 名字(类属性)
self.hp = hp # 生命(类属性)
self.attack = attack # 攻击力(类属性)
def ypgrade(): # 用关键字def定义方法名,封装函数
yase.level=yase.level+1 # 每升级一次等级+1
yese.hp=yase.hp+50 # 。。。。 血量+50
yase.attack=yase.attack+4 # 。。。。 攻击力+4
yase = Hero("亚瑟",300,20) # 括号内实参123分别对应形参123
print("亚瑟的初始血量为: ",yase.hp)
upgrade() # 重复调用函数
upgrade() # 重复调用函数
print("升级2次后,亚瑟的血量为: ",yase.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