This code should take a list of viruses like [ATCG, GTAC.....] and a mortalityProb (float between 0 and 1) that represents the chance of a virus to die / get deleted from the list.
The function should return a new list with the remaining viruses. Each of the viruses has an individual chance to die, so with a mortalityProb of say 0.6 there should be around 60% of the viruses remaining.
It should be doable in 2 lines (including def kill(viruses, mortalityProb):) and my line of code using list comprehensions.
def kill(viruses, mortalityProb):
for i in viruses:
if random.randint(0, 100) < (mortalityProb * 100):
del i
return viruses
This does not quite work though, but I can't get a grasp on why...
Aucun commentaire:
Enregistrer un commentaire