import random
class game:
def __init__(self):
self.hp = random.randint(1,20)
self.dmg = random.randint(1,15)
self.regn = random.randint(1,3)
self.stab = 3-self.hp
def player(self):
print("Health")
print(self.hp)
print("Damage")
print(self.dmg)
print("Regen")
print(self.regn)
def Mob_1(self):
hit = self.hp - 3
if 1 == 1 :
print("you were hit")
hit
self.mob1_hp=8
self.mob1_dmg=4
while self.mob1_hp <= 0:
hit
self.mob1_hp -= self.dmg
print(self.mob1_hp)
goblin = Mob_1('self')
def day_1(self,goblin):
print("\nIt day one")
goblin
第一个功能工作正常player(self)
,而是试图做另外一个时,我得到一个断言错误。为了解释我制作妖精的原因,我可以一次性调用整个功能(或者这就是它所要做的)。特别的错误是形成hit = self.hp - 3
代码行。更多的澄清这里是错误消息:我得到断言错误,我不知道为什么
Traceback (most recent call last):
line 3, in <module>
class game:
line 33, in game
goblin = Mob_1('self')
line 20, in Mob_1
hit = self.hp - 3
AttributeError: 'str' object has no attribute 'hp'
PS我很新的这个网站我已经看过过去的问题寻求帮助,但我似乎无法找到一种方法来解决它
的'AttributeError'是不是'AssertionError'不同的事情。 – Blckknght