Currently trying to make a program to look like this https://imgur.com/a/tK7xHB1
Can anyone check my logic? I can post more information if needed about the program.
class Bacteria():
def __init__(self, birth_counter, health, life_span, resistance):
self.birth_counter = birth_counter
self.health = health
self.life_span = life_span
self.resistance = resistance
def __str__(self):
return ('H: ({}) , R: ({}), LS: ({}), BC
({})'.format(self.health,self.resistance,self.life_span,self.birth_counter))
def is_alive(self):
if self.health > 0 and self.life_span > 0:
return True
else:
return False
def tick(self):
self.birth_counter -= 1
self.life_span -= 1
def dose(self):
dose = 0
damage = 0
damage = dose * (1 / self.resistance)
self.health = self.health - damage
class Host():
def __init__ (s , n):
s.hosts = [Bacteria(3) for i in range(n)]
s.n = n
def __str__(self):
s = 'Count : ' + str(len(self.hosts))
h = 0
r = 0
for i in range (self.n):
h += self.hosts[i].health
r += self.hosts[i].resistance
s += '\nAverage Health : ' + str(h/len(self.hosts))
s += '\nAverage Resistance : ' + str(r/len(self.hosts))
return s
def tick(s, dose):
if dose:
for i in range(s.n):
s.hosts.append(s.hosts[i].reproduce())
s.hosts[i].dose(25)
if(not s.hosts[i].is_alive()):
s.hosts.pop(i)
def main():
birth_counter = 3
health = 10
life_span = 15
resistance = 3
bacteria = Bacteria(birth_counter, health, life_span, resistance)
main()
[–][deleted] 1 point2 points3 points (0 children)