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