Commit 59414d18 by BellCodeEditor

save project

parent a832a717
Showing with 11 additions and 13 deletions
class Hero:
def __init__(self,hp,name,attack):
def __init__(self, hp, name, attack):
self.hp = hp
self.name = name
self.attack = attack
self.lv = 1
xiaoming = Hero(10,"小明",2)
xiaohong = Hero(25,"小红",10)
print(xiaoming.name,"击败了",xiaohong.name,"的等级增加一级")
def upup():
xiaoming.lv = xiaoming.lv+1
xiaoming.hp = xiaoming.hp+1
xiaoming.attack = xiaoming.attack+1
print('现在',xiaoming.name,"的等级为",xiaoming.lv,"血量为",xiaoming.hp,"攻击力为",xiaoming.attack)
print(xiaoming.name,"的攻击力为",xiaoming.attack)
print(xiaohong.name,"的攻击力为",xiaohong.attack)
upup()
\ No newline at end of file
xiaoming = Hero(10, "小明", 2)
xiaohong = Hero(25, "小红", 10)
print(xiaoming.name, "击败了", xiaohong.name, "的等级增加一级")
def upup(name):
name.lv = name.lv+1
name.hp = name.hp+1
name.attack = name.attack+1
print('现在', name.name, "的等级为", name.lv,"血量为", name.hp, "攻击力为", name.attack)
upup(xiaoming)
\ 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