Reputation: 11
I was trying to create a game.. (In Python) I made some objects with the same class. Then I made a function with (*) in the argument to get as many arg. as I want. But I guess, I got a tuple and now I need to iterate over all the object's attribute in an 'if' condition (attribute is a boolean). Please help! 🥺
Raihan=Hero(name='Raihan',health = 200,weapon=Sword)
Cobra=Enemy(name='Cobra' ,health=140,weapon=Bow)
def valid(\*opponents: Character,\*,self):
if self.health and >(opponents.health or opponents.health) != 0:
return True
else:
return False
def main():
Raihan.equip(Sword)
input()
while valid(Cobra, self=Raihan):
os.system('clear')
Raihan.attack(Cobra)
Cobra.attack(Raihan)
input()
Upvotes: 0
Views: 20
Reputation: 11
This works!
def valid(*opponents: Character, self: Character):
if self.health and sum([i.health for i in opponents]) != 0:
return True
else:
return False
Upvotes: 1