dimanche 12 juin 2016

Simultaneous while loops ? PYTHON


Currently the code below works, but I should have a disease factor and a population number trigger to go along with it. Basically the juvenile and seniles can be affected by disease, but only once the total population reaches a 'trigger point' set by the user. I'm not sure how to do this, as if I put an extra clause onto the while loop which the population does not satisfy, I could create another while loop to use, but then the generation/counter thing won't work. By the way, the stuff at the beginning of the code is to do with the class stuff I'm using, just ignore it.

print ("This is where you run the python model")

adult_population = Gen0.adult_population
birth_rate = Gen0.birth_rate
juvenile_population = Gen0.juvenile_population
juvenile_survival = Gen0.juvenile_survival
adult_population = Gen0.adult_population
adult_survival = Gen0.adult_survival
senile_population = Gen0.senile_population
senile_survival = Gen0.senile_survival
disease = Gen0.disease
disease_trigger = Gen0.disease_trigger
generations = Gen0.generations

counter = 0


while counter < generations:

    new_juvenile_population = adult_population * birth_rate
    new_adult_population = juvenile_population * juvenile_survival
    new_senile_population = (adult_population * adult_survival) + (senile_population * senile_survival)
    new_total = new_juvenile_population + new_adult_population + new_senile_population

    print("Juveniles:" ,new_juvenile_population)
    print("Adults:" ,new_adult_population)
    print("Seniles:" ,new_senile_population)
    print("Total population:" ,new_total)

    juvenile_population = new_juvenile_population
    adult_population = new_adult_population
    senile_population = new_senile_population

    counter += 1

Aucun commentaire:

Enregistrer un commentaire