|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
如题以下代码不知道哪里有问题,求修改
import time
class Role:
def __init__(self,name,hp):
self.name=name
self.hp=hp
def tong(self,enemy):
enemy.hp-=10
info='【%S】捅了【%s】一刀'%(self.name,enemy.name)
def kanren(self,enemy):
ememy.hp-=15
info='【%S】砍了【%s】一刀'%(self.name,enemy.name)
def chiyao(self):
self.hp+=10
info='【%S】吃了一口药'%(self.name)
def __str__(self):
return '%S还剩下%s的血量'%(self.name,self.hp)
xmcx=Role('西门吹雪',100)
ygc=Role('叶孤城',100)
while True:
if xmcx.hp<0 or ygc.hp<0:
break
xmcx.tong(ygc)
print(ygc)
print(xmcx)
print('**************************************')
ygc.tong(xmcx)
print(ygc)
print(xmcx)
print('**************************************')
xmcx.chiyao()
print(ygc)
print(xmcx)
time.sleep(1)
%s用小写,大写没有意义
- import time
- class Role:
- def __init__(self,name,hp):
- self.name=name
- self.hp=hp
- def tong(self,enemy):
- enemy.hp-=10
- info='【%s】捅了【%s】一刀'%(self.name,enemy.name)
- def kanren(self,enemy):
- ememy.hp-=15
- info='【%s】砍了【%s】一刀'%(self.name,enemy.name)
- def chiyao(self):
- self.hp+=10
- info='【%s】吃了一口药'%(self.name)
- def __str__(self):
- return '%s还剩下%s的血量'%(self.name,self.hp)
- xmcx=Role('西门吹雪',100)
- ygc=Role('叶孤城',100)
- while True:
- if xmcx.hp<0 or ygc.hp<0:
- break
- xmcx.tong(ygc)
- print(ygc)
- print(xmcx)
- print('**************************************')
- ygc.tong(xmcx)
- print(ygc)
- print(xmcx)
- print('**************************************')
- xmcx.chiyao()
- print(ygc)
- print(xmcx)
- time.sleep(1)
复制代码
|
|