I’m making an enemy class for a small text based game and this is the code so far:
import random class enemy: def __init__(self, enemyname, hp, dmg): self.enemyname = enemyname self.hp = hp self.dmg = dmg def __str__(self): return f"{self.hp}, {self.dmg}" def attack(self): print("The", self.enemyname, "does", self.dmg, "damage to you!") if self.dmg == _____: print("Critical Hit!") boar = enemy("boar", 10, (random.randint(25, 50) / 10)) boar.attack()
The thing I want to do is have the function identify the highest number in the randint function. In the boar’s case, this would be 5.0. The reason I haven’t just written 5.0 is because I’m going to add other enemies who may have higher or lower max damages. If anything more needs to be explained, please ask.
submitted by /u/Greedy-Researcher-59
[link] [comments]
r/learnpython I’m making an enemy class for a small text based game and this is the code so far: import random class enemy: def __init__(self, enemyname, hp, dmg): self.enemyname = enemyname self.hp = hp self.dmg = dmg def __str__(self): return f”{self.hp}, {self.dmg}” def attack(self): print(“The”, self.enemyname, “does”, self.dmg, “damage to you!”) if self.dmg == _____: print(“Critical Hit!”) boar = enemy(“boar”, 10, (random.randint(25, 50) / 10)) boar.attack() The thing I want to do is have the function identify the highest number in the randint function. In the boar’s case, this would be 5.0. The reason I haven’t just written 5.0 is because I’m going to add other enemies who may have higher or lower max damages. If anything more needs to be explained, please ask. submitted by /u/Greedy-Researcher-59 [link] [comments]
I’m making an enemy class for a small text based game and this is the code so far:
import random class enemy: def __init__(self, enemyname, hp, dmg): self.enemyname = enemyname self.hp = hp self.dmg = dmg def __str__(self): return f"{self.hp}, {self.dmg}" def attack(self): print("The", self.enemyname, "does", self.dmg, "damage to you!") if self.dmg == _____: print("Critical Hit!") boar = enemy("boar", 10, (random.randint(25, 50) / 10)) boar.attack()
The thing I want to do is have the function identify the highest number in the randint function. In the boar’s case, this would be 5.0. The reason I haven’t just written 5.0 is because I’m going to add other enemies who may have higher or lower max damages. If anything more needs to be explained, please ask.
submitted by /u/Greedy-Researcher-59
[link] [comments]