位置参数OSX
问题描述:
MAC终端说传递两个位置参数到take_damage方法IM ...位置参数OSX
from enemy import Enemy
random_monster = Enemy("Basic enemy", 12, 1)
print(random_monster)
random_monster.take_damage(4)
print(random_monster)
及其他文件在这里______________________
class Enemy:
def __init__(self, name="Enemy", hit_points = 0, lives = 1):
self.name = name
self.hit_points = hit_points
self.lives = lives
def take_damage(damage):
remaining_points = self.hit_points - take_damage
if remaining_points >= 0:
self.hit_points = remaining_points
print("i took {} damage and have {} left".format(damage, self.hit_points))
else:
self.lives -= 1
def __str__(self):
return "Name: {0.name}, Lives: {0.lives}, Hitpoints: {0.hit_points}".format(self)
答
的所有方法都需要采取self
以及作为任何其他论点。
def take_damage(self, damage):
ahh想通了,谢谢你!我也试图减去take_damage而不是损坏。愚蠢的学习错误大声笑 – KeatonBenning